commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r907451 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java xdocs/changes.xml
Date Sun, 07 Feb 2010 17:20:44 GMT
Author: oheger
Date: Sun Feb  7 17:20:44 2010
New Revision: 907451

URL: http://svn.apache.org/viewvc?rev=907451&view=rev
Log:
[CONFIGURATION-407] Synchronized access to nodes when constructing the global section configuration.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java?rev=907451&r1=907450&r2=907451&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalINIConfiguration.java
Sun Feb  7 17:20:44 2010
@@ -714,7 +714,10 @@
             ConfigurationNode node = (ConfigurationNode) it.next();
             if (!isSectionNode(node))
             {
-                parent.addChild(node);
+                synchronized (node)
+                {
+                    parent.addChild(node);
+                }
             }
         }
 

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java?rev=907451&r1=907450&r2=907451&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalINIConfiguration.java
Sun Feb  7 17:20:44 2010
@@ -513,6 +513,27 @@
     }
 
     /**
+     * Tests concurrent access to the global section.
+     */
+    public void testGetSectionGloabalMultiThreaded()
+            throws ConfigurationException, InterruptedException
+    {
+        HierarchicalINIConfiguration config = setUpConfig(INI_DATA_GLOBAL);
+        final int threadCount = 10;
+        GlobalSectionTestThread[] threads = new GlobalSectionTestThread[threadCount];
+        for (int i = 0; i < threadCount; i++)
+        {
+            threads[i] = new GlobalSectionTestThread(config);
+            threads[i].start();
+        }
+        for (int i = 0; i < threadCount; i++)
+        {
+            threads[i].join();
+            assertFalse("Exception occurred", threads[i].error);
+        }
+    }
+
+    /**
      * Tests querying the content of the global section if there is none.
      */
     public void testGetSectionGlobalNonExisting() throws ConfigurationException
@@ -608,4 +629,48 @@
         assertEquals("Wrong value", "one" + LINE_SEPARATOR, config
                 .getString("section5.continueNoLine"));
     }
+
+    /**
+     * A thread class for testing concurrent access to the global section.
+     */
+    private static class GlobalSectionTestThread extends Thread
+    {
+        /** The configuration. */
+        private final HierarchicalINIConfiguration config;
+
+        /** A flag whether an error was found. */
+        volatile boolean error;
+
+        /**
+         * Creates a new instance of <code>GlobalSectionTestThread</code> and
+         * initializes it.
+         *
+         * @param conf the configuration object
+         */
+        public GlobalSectionTestThread(HierarchicalINIConfiguration conf)
+        {
+            config = conf;
+        }
+
+        /**
+         * Accesses the global section in a loop. If there is no correct
+         * synchronization, this can cause an exception.
+         */
+        public void run()
+        {
+            final int loopCount = 250;
+
+            for (int i = 0; i < loopCount && !error; i++)
+            {
+                try
+                {
+                    config.getSection(null);
+                }
+                catch (IllegalStateException istex)
+                {
+                    error = true;
+                }
+            }
+        }
+    }
 }

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=907451&r1=907450&r2=907451&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sun Feb  7 17:20:44 2010
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.7" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-407">
+        Fixed a potential IllegalStateException in HierarchicalINIConfiguration
+        that can be thrown when the global section is requested concurrently.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-405">
         XMLPropertyListConfiguration no longer throws a ConfigurationException
         if the file to be loaded does not have an outer dict element.



Mime
View raw message