You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/07/30 21:59:36 UTC

svn commit: r1367253 - in /commons/proper/configuration/trunk/src: changes/ main/java/org/apache/commons/configuration/plist/ test/java/org/apache/commons/configuration/plist/ test/resources/

Author: oheger
Date: Mon Jul 30 19:59:36 2012
New Revision: 1367253

URL: http://svn.apache.org/viewvc?rev=1367253&view=rev
Log:
[CONFIGURATION-501] XMLPropertyListConfiguration now logs a warning for an invalid date property rather than swallowing the parsing exception.

Added:
    commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml   (with props)
Modified:
    commons/proper/configuration/trunk/src/changes/changes.xml
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java

Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1367253&r1=1367252&r2=1367253&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Mon Jul 30 19:59:36 2012
@@ -27,6 +27,10 @@
   <body>
     <release version="1.9" date="in SVN"
       description="TBD">
+      <action dev="oheger" type="add" issue="CONFIGURATION-501">
+        XMLPropertyListConfiguration no longer swallows exception caused by
+        invalid date properties. Now a warning message is logged.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-495">
         List properties can now be set correctly on a HierarchicalConfiguration
         if delimiter parsing is disabled.

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?rev=1367253&r1=1367252&r2=1367253&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java Mon Jul 30 19:59:36 2012
@@ -459,7 +459,7 @@ public class XMLPropertyListConfiguratio
     /**
      * SAX Handler to build the configuration nodes while the document is being parsed.
      */
-    private static class XMLPropertyListHandler extends DefaultHandler
+    private class XMLPropertyListHandler extends DefaultHandler
     {
         /** The buffer containing the text node being read */
         private StringBuilder buffer = new StringBuilder();
@@ -578,7 +578,15 @@ public class XMLPropertyListConfiguratio
                 }
                 else if ("date".equals(qName))
                 {
-                    ((PListNode) peek()).addDateValue(buffer.toString());
+                    try
+                    {
+                        ((PListNode) peek()).addDateValue(buffer.toString());
+                    }
+                    catch (IllegalArgumentException iex)
+                    {
+                        getLogger().warn(
+                                "Ignoring invalid date property " + buffer);
+                    }
                 }
                 else if ("array".equals(qName))
                 {
@@ -660,6 +668,7 @@ public class XMLPropertyListConfiguratio
          * Parse the specified string as a date and add it to the values of the node.
          *
          * @param value the value to be added
+         * @throws IllegalArgumentException if the date string cannot be parsed
          */
         public void addDateValue(String value)
         {
@@ -684,7 +693,8 @@ public class XMLPropertyListConfiguratio
             }
             catch (ParseException e)
             {
-                // ignore
+                throw new IllegalArgumentException(String.format(
+                        "'%s' cannot be parsed to a date!", value), e);
             }
         }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java?rev=1367253&r1=1367252&r2=1367253&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java Mon Jul 30 19:59:36 2012
@@ -392,4 +392,18 @@ public class TestXMLPropertyListConfigur
                 ConfigurationAssert.getTestFile("test2.plist.xml"));
         assertFalse("Configuration is empty", plist.isEmpty());
     }
+
+    /**
+     * Tests a configuration file which contains an invalid date property value.
+     * This test is related to CONFIGURATION-501.
+     */
+    @Test
+    public void testSetDatePropertyInvalid() throws ConfigurationException
+    {
+        config.clear();
+        config.setFile(ConfigurationAssert.getTestFile("test_invalid_date.plist.xml"));
+        config.load();
+        assertEquals("'string' property", "value1", config.getString("string"));
+        assertFalse("Date property was loaded", config.containsKey("date"));
+    }
 }

Added: commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml?rev=1367253&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml (added)
+++ commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml Mon Jul 30 19:59:36 2012
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<!-- Test configuration file with an invalid date property.
+     $Id$
+-->
+<plist version="1.0">
+    <dict>
+
+        <key>string</key>
+        <string>value1</string>
+
+        <key>date</key>
+        <date>not a valid date</date>
+
+    </dict>
+</plist>

Propchange: commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/src/test/resources/test_invalid_date.plist.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml