commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r903550 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/tree/ src/test/org/apache/commons/configuration/ src/test/org/apache/commons/configuration/tree/ xdocs/
Date Wed, 27 Jan 2010 06:44:08 GMT
Author: oheger
Date: Wed Jan 27 06:43:50 2010
New Revision: 903550

URL: http://svn.apache.org/viewvc?rev=903550&view=rev
Log:
[CONFIGURATION-404] DefaultConfigurationKey.KeyIterator no longer throws a NumberFormatException
if a key contains brackets, but no valid index value. Thanks to Rob Walker for the patch.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/DefaultConfigurationKey.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestDefaultConfigurationKey.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/DefaultConfigurationKey.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/DefaultConfigurationKey.java?rev=903550&r1=903549&r2=903550&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/DefaultConfigurationKey.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/DefaultConfigurationKey.java
Wed Jan 27 06:43:50 2010
@@ -823,20 +823,26 @@
         {
             boolean result = false;
 
-            int idx = key.lastIndexOf(getExpressionEngine().getIndexStart());
-            if (idx > 0)
+            try
             {
-                int endidx = key.indexOf(getExpressionEngine().getIndexEnd(),
-                        idx);
-
-                if (endidx > idx + 1)
+                int idx = key.lastIndexOf(getExpressionEngine().getIndexStart());
+                if (idx > 0)
                 {
-                    indexValue = Integer.parseInt(key
-                            .substring(idx + 1, endidx));
-                    current = key.substring(0, idx);
-                    result = true;
+                    int endidx = key.indexOf(getExpressionEngine().getIndexEnd(),
+                            idx);
+    
+                    if (endidx > idx + 1)
+                    {
+                        indexValue = Integer.parseInt(key.substring(idx + 1, endidx));
+                        current = key.substring(0, idx);
+                        result = true;
+                    }
                 }
             }
+            catch (NumberFormatException nfe)
+            {
+                result = false;
+            }
 
             return result;
         }

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=903550&r1=903549&r2=903550&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Wed Jan 27 06:43:50 2010
@@ -1005,6 +1005,16 @@
         assertEquals("Wrong number of children", 2, oldRoot.getChildrenCount());
     }
 
+    /**
+     * Tests whether keys that contains brackets can be used.
+     */
+    public void testGetPropertyKeyWithBrackets()
+    {
+        final String key = "test.directory.platform(x86)";
+        config.addProperty(key, "C:\\Temp");
+        assertEquals("Wrong property value", "C:\\Temp", config.getString(key));
+    }
+
 	/**
      * Helper method for testing the getKeys(String) method.
      *

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestDefaultConfigurationKey.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestDefaultConfigurationKey.java?rev=903550&r1=903549&r2=903550&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestDefaultConfigurationKey.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestDefaultConfigurationKey.java
Wed Jan 27 06:43:50 2010
@@ -434,6 +434,25 @@
     }
 
     /**
+     * Tests whether a key with brackets in it can be iterated over.
+     */
+    public void testIterateWithBrackets()
+    {
+        key.append("directory.platform(x86).path");
+        DefaultConfigurationKey.KeyIterator kit = key.iterator();
+        String part = kit.nextKey();
+        assertEquals("Wrong part 1", "directory", part);
+        assertFalse("Has index 1", kit.hasIndex());
+        part = kit.nextKey();
+        assertEquals("Wrong part 2", "platform(x86)", part);
+        assertFalse("Has index 2", kit.hasIndex());
+        part = kit.nextKey();
+        assertEquals("Wrong part 3", "path", part);
+        assertFalse("Has index 3", kit.hasIndex());
+        assertFalse("Too many elements", kit.hasNext());
+    }
+
+    /**
      * Tests iterating over an attribute key that has an index.
      */
     public void testAttributeKeyWithIndex()

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=903550&r1=903549&r2=903550&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Wed Jan 27 06:43:50 2010
@@ -27,6 +27,12 @@
         XMLPropertyListConfiguration no longer throws a ConfigurationException
         if the file to be loaded does not have an outer dict element.
       </action>
+      <action dev="oheger" type="fix" issue="CONFIGURATION-404" due-to="Rob Walker">
+        The default expression engine used by hierarchical configurations used to
+        throw a NumberFormatException if invalid indices were used in property
+        keys. This has been fixed. As a side effect brackets can now be used in
+        property keys.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-403">
         When an empty XMLConfiguration was saved and reloaded the root element
         was assigned an empty text value. Because of this isEmpty() returned



Mime
View raw message