commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1590417 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/CombinedConfiguration.java test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
Date Sun, 27 Apr 2014 16:50:19 GMT
Author: oheger
Date: Sun Apr 27 16:50:19 2014
New Revision: 1590417

URL: http://svn.apache.org/r1590417
Log:
[CONFIGURATION-572] Fixed a possible memory leak.

When a CombinedConfiguration is cleared it is now ensured that change listener
registrations are removed for all child configurations.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java?rev=1590417&r1=1590416&r2=1590417&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
Sun Apr 27 16:50:19 2014
@@ -655,6 +655,7 @@ public class CombinedConfiguration exten
     @Override
     protected void clearInternal()
     {
+        unregisterListenerAtChildren();
         initChildCollections();
         invalidateInternal();
     }
@@ -972,6 +973,21 @@ public class CombinedConfiguration exten
     }
 
     /**
+     * Removes this combined configuration as listener from all child
+     * configurations. This method is called on a clear() operation.
+     */
+    private void unregisterListenerAtChildren()
+    {
+        if (configurations != null)
+        {
+            for (ConfigData child : configurations)
+            {
+                unregisterListenerAt(child.getConfiguration());
+            }
+        }
+    }
+
+    /**
      * Returns the number of child configurations in this combined
      * configuration. The internal list of child configurations is accessed
      * without synchronization.

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java?rev=1590417&r1=1590416&r2=1590417&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
Sun Apr 27 16:50:19 2014
@@ -18,6 +18,7 @@ package org.apache.commons.configuration
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
@@ -450,6 +451,24 @@ public class TestCombinedConfiguration
     }
 
     /**
+     * Tests whether the combined configuration removes itself as change
+     * listener from the child configurations on a clear operation. This test is
+     * related to CONFIGURATION-572.
+     */
+    @Test
+    public void testClearRemoveChildListener()
+    {
+        AbstractConfiguration child = setUpTestConfiguration();
+        config.addConfiguration(child);
+
+        config.clear();
+        for (ConfigurationListener listener : child.getConfigurationListeners())
+        {
+            assertNotEquals("Still registered", config, listener);
+        }
+    }
+
+    /**
      * Prepares a test of the getSource() method.
      */
     private void setUpSourceTest()



Mime
View raw message