Author: oheger Date: Tue Aug 28 08:56:49 2007 New Revision: 570462 URL: http://svn.apache.org/viewvc?rev=570462&view=rev Log: Fixed tests that were failing under JDK 6
Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestBeanHelper.java Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java?rev=570462&r1=570461&r2=570462&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java (original) +++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java Tue Aug 28 08:56:49 2007 @@ -341,6 +341,7 @@ super(); providers = new HashMap(); registerDefaultProviders(); + registerBeanFactory(); setLogger(LogFactory.getLog(getClass())); addErrorLogListener(); // log errors per default } @@ -698,6 +699,24 @@ } /** + * Registers the bean factory used by this class if necessary. This method + * is called by the constructor to ensure that the required bean factory is + * available. + */ + private void registerBeanFactory() + { + synchronized (getClass()) + { + if (!BeanHelper.registeredFactoryNames().contains( + CONFIG_BEAN_FACTORY_NAME)) + { + BeanHelper.registerBeanFactory(CONFIG_BEAN_FACTORY_NAME, + new ConfigurationBeanFactory()); + } + } + } + + /** * <p> * A base class for creating and initializing configuration sources. * </p> @@ -1388,12 +1407,5 @@ { return new CombinedConfiguration(); } - } - - static - { - // register the configuration bean factory - BeanHelper.registerBeanFactory(CONFIG_BEAN_FACTORY_NAME, - new ConfigurationBeanFactory()); } } Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java?rev=570462&r1=570461&r2=570462&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java (original) +++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java Tue Aug 28 08:56:49 2007 @@ -17,6 +17,7 @@ package org.apache.commons.configuration.beanutils; import java.lang.reflect.InvocationTargetException; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -55,7 +56,7 @@ public class BeanHelper { /** Stores a map with the registered bean factories. */ - private static Map beanFactories = new HashMap(); + private static Map beanFactories = Collections.synchronizedMap(new HashMap()); /** * Stores the default bean factory, which will be used if no other factory Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestBeanHelper.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestBeanHelper.java?rev=570462&r1=570461&r2=570462&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestBeanHelper.java (original) +++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestBeanHelper.java Tue Aug 28 08:56:49 2007 @@ -46,11 +46,24 @@ { super.setUp(); tempDefaultBeanFactory = BeanHelper.getDefaultBeanFactory(); + deregisterFactories(); } protected void tearDown() throws Exception { - // Remove all bean factories that might have been registered + deregisterFactories(); + + // Reset old default bean factory + BeanHelper.setDefaultBeanFactory(tempDefaultBeanFactory); + + super.tearDown(); + } + + /** + * Removes all bean factories that might have been registered during a test. + */ + private void deregisterFactories() + { for (Iterator it = BeanHelper.registeredFactoryNames().iterator(); it .hasNext();) { @@ -58,11 +71,6 @@ } assertTrue("Remaining registered bean factories", BeanHelper .registeredFactoryNames().isEmpty()); - - // Reset old default bean factory - BeanHelper.setDefaultBeanFactory(tempDefaultBeanFactory); - - super.tearDown(); } /**