commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1231760 - in /commons/proper/configuration/trunk/src: changes/changes.xml main/java/org/apache/commons/configuration/CompositeConfiguration.java test/java/org/apache/commons/configuration/TestCompositeConfiguration.java
Date Sun, 15 Jan 2012 21:32:27 GMT
Author: oheger
Date: Sun Jan 15 21:32:26 2012
New Revision: 1231760

URL: http://svn.apache.org/viewvc?rev=1231760&view=rev
Log:
[CONFIGURATION-476] Before casting the in-memory configuration it is checked whether the cast
is possible.

Modified:
    commons/proper/configuration/trunk/src/changes/changes.xml
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CompositeConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCompositeConfiguration.java

Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1231760&r1=1231759&r2=1231760&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Sun Jan 15 21:32:26 2012
@@ -27,6 +27,10 @@
   <body>
     <release version="1.8" date="in SVN"
       description="TBD">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-476">
+        Fixed possible ClassCastExceptions in CompositeConfiguration related to
+        special in-memory configurations.
+      </action>
       <action dev="oheger" type="update" issue="CONFIGURATION-475">
         Class ConfigurationKey was deprecated in favour of DefaultConfigurationKey.
       </action>

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CompositeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CompositeConfiguration.java?rev=1231760&r1=1231759&r2=1231760&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CompositeConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CompositeConfiguration.java
Sun Jan 15 21:32:26 2012
@@ -327,7 +327,7 @@ implements Cloneable
      */
     public Configuration getConfiguration(int index)
     {
-        return (Configuration) configList.get(index);
+        return configList.get(index);
     }
 
     /**
@@ -393,8 +393,11 @@ implements Cloneable
     @Override
     public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
     {
-        ((BaseConfiguration) getInMemoryConfiguration())
-                .setDelimiterParsingDisabled(delimiterParsingDisabled);
+        if (inMemoryConfiguration instanceof AbstractConfiguration)
+        {
+            ((AbstractConfiguration) inMemoryConfiguration)
+                    .setDelimiterParsingDisabled(delimiterParsingDisabled);
+        }
         super.setDelimiterParsingDisabled(delimiterParsingDisabled);
     }
 
@@ -408,8 +411,11 @@ implements Cloneable
     @Override
     public void setListDelimiter(char listDelimiter)
     {
-        ((BaseConfiguration) getInMemoryConfiguration())
-                .setListDelimiter(listDelimiter);
+        if (inMemoryConfiguration instanceof AbstractConfiguration)
+        {
+            ((AbstractConfiguration) inMemoryConfiguration)
+                    .setListDelimiter(listDelimiter);
+        }
         super.setListDelimiter(listDelimiter);
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCompositeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCompositeConfiguration.java?rev=1231760&r1=1231759&r2=1231760&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCompositeConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCompositeConfiguration.java
Sun Jan 15 21:32:26 2012
@@ -39,6 +39,7 @@ import java.util.NoSuchElementException;
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
 import org.apache.commons.configuration.reloading.FileAlwaysReloadingStrategy;
+import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -847,6 +848,34 @@ public class TestCompositeConfiguration
     }
 
     /**
+     * Tests the behavior of setListDelimiter() if the in-memory configuration
+     * is not derived from BaseConfiguration. This test is related to
+     * CONFIGURATION-476.
+     */
+    @Test
+    public void testSetListDelimiterInMemoryConfigNonBaseConfig()
+    {
+        Configuration inMemoryConfig = EasyMock.createMock(Configuration.class);
+        EasyMock.replay(inMemoryConfig);
+        cc = new CompositeConfiguration(inMemoryConfig);
+        cc.setListDelimiter(';');
+    }
+
+    /**
+     * Tests the behavior of setDelimiterParsingDisabled() if the in-memory
+     * configuration is not derived from BaseConfiguration. This test is related
+     * to CONFIGURATION-476.
+     */
+    @Test
+    public void testSetDelimiterParsingDisabledInMemoryConfigNonBaseConfig()
+    {
+        Configuration inMemoryConfig = EasyMock.createMock(Configuration.class);
+        EasyMock.replay(inMemoryConfig);
+        cc = new CompositeConfiguration(inMemoryConfig);
+        cc.setDelimiterParsingDisabled(true);
+    }
+
+    /**
      * A test configuration event listener that counts the number of received
      * events. Used for testing the event facilities.
      */



Mime
View raw message