commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1481153 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java test/java/org/apache/commons/configuration/TestBaseHierarchicalConfigurationSynchronization.java
Date Fri, 10 May 2013 19:16:00 GMT
Author: oheger
Date: Fri May 10 19:15:59 2013
New Revision: 1481153

URL: http://svn.apache.org/r1481153
Log:
In the copy constructor of BaseHierarchicalConfiguration the passed in configuration is now
locked.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseHierarchicalConfigurationSynchronization.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java?rev=1481153&r1=1481152&r2=1481153&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
Fri May 10 19:15:59 2013
@@ -30,6 +30,7 @@ import java.util.Stack;
 
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.sync.LockMode;
 import org.apache.commons.configuration.sync.NoOpSynchronizer;
 import org.apache.commons.configuration.sync.Synchronizer;
 import org.apache.commons.configuration.tree.ConfigurationNode;
@@ -197,9 +198,7 @@ public class BaseHierarchicalConfigurati
         this();
         if (c != null)
         {
-            CloneVisitor visitor = new CloneVisitor();
-            c.getRootNode().visit(visitor);
-            rootNode = visitor.getClone();
+            rootNode = copyRootNode(c);
         }
     }
 
@@ -1263,6 +1262,28 @@ public class BaseHierarchicalConfigurati
     }
 
     /**
+     * Creates a copy of the node structure of the passed in configuration.
+     *
+     * @param c the configuration whose nodes are to be copied
+     * @return the copied root node
+     */
+    private static ConfigurationNode copyRootNode(HierarchicalConfiguration c)
+    {
+        CloneVisitor visitor = new CloneVisitor();
+        c.lock(LockMode.READ);
+        try
+        {
+            c.getRootNode().visit(visitor);
+        }
+        finally
+        {
+            c.unlock(LockMode.READ);
+        }
+        ConfigurationNode nd = visitor.getClone();
+        return nd;
+    }
+
+    /**
      * A specialized visitor that checks if a node is defined.
      * "Defined" in this terms means that the node or at least one of
      * its sub nodes is associated with a value.

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseHierarchicalConfigurationSynchronization.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseHierarchicalConfigurationSynchronization.java?rev=1481153&r1=1481152&r2=1481153&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseHierarchicalConfigurationSynchronization.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseHierarchicalConfigurationSynchronization.java
Fri May 10 19:15:59 2013
@@ -118,4 +118,16 @@ public class TestBaseHierarchicalConfigu
         config.setRootNode(new DefaultConfigurationNode("testRoot"));
         sync.verify(Methods.BEGIN_WRITE, Methods.END_WRITE);
     }
+
+    /**
+     * Tests whether synchronization is performed when copying a configuration.
+     */
+    @Test
+    public void testCopyConstructorSynchronized()
+    {
+        BaseHierarchicalConfiguration copy =
+                new BaseHierarchicalConfiguration(config);
+        sync.verify(Methods.BEGIN_READ, Methods.END_READ);
+        assertNotSame("Synchronizer was copied", sync, copy.getSynchronizer());
+    }
 }



Mime
View raw message