Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 89282 invoked from network); 27 Jan 2010 06:44:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Jan 2010 06:44:50 -0000 Received: (qmail 28781 invoked by uid 500); 27 Jan 2010 06:44:50 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 28382 invoked by uid 500); 27 Jan 2010 06:44:48 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 28373 invoked by uid 99); 27 Jan 2010 06:44:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jan 2010 06:44:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jan 2010 06:44:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 98B7023889C5; Wed, 27 Jan 2010 06:44:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100127064426.98B7023889C5@eris.apache.org> 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. + + 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. + When an empty XMLConfiguration was saved and reloaded the root element was assigned an empty text value. Because of this isEmpty() returned