commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1772266 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/XMLConfiguration.java test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Date Thu, 01 Dec 2016 20:53:13 GMT
Author: oheger
Date: Thu Dec  1 20:53:13 2016
New Revision: 1772266

URL: http://svn.apache.org/viewvc?rev=1772266&view=rev
Log:
[CONFIGURATION-641] Improved exception thrown by load().

XMLConfiguration.load() now checks whether the locator has been
correctly initialized. If not, an exception with a helpful message
is thrown.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java?rev=1772266&r1=1772265&r2=1772266&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
Thu Dec  1 20:53:13 2016
@@ -962,6 +962,13 @@ public class XMLConfiguration extends Ba
      */
     private void load(InputSource source) throws ConfigurationException
     {
+        if (locator == null)
+        {
+            throw new ConfigurationException("Load operation not properly "
+                    + "initialized! Do not call read(InputStream) directly,"
+                    + " but use a FileHandler to load a configuration.");
+        }
+
         try
         {
             URL sourceURL = locator.getSourceURL();

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java?rev=1772266&r1=1772265&r2=1772266&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Thu Dec  1 20:53:13 2016
@@ -1622,6 +1622,28 @@ public class TestXMLConfiguration
     }
 
     /**
+     * Tests a direct invocation of the read() method. This is not allowed
+     * because certain initializations have not been done. This test is
+     * related to CONFIGURATION-641.
+     */
+    @Test
+    public void testReadCalledDirectly() throws IOException, ConfigurationException
+    {
+        conf = new XMLConfiguration();
+        String content = "<configuration><test>1</test></configuration>";
+        ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes());
+        try
+        {
+            conf.read(bis);
+            fail("No exception thrown!");
+        }
+        catch (ConfigurationException e)
+        {
+            assertThat(e.getMessage(), containsString("FileHandler"));
+        }
+    }
+
+    /**
      * Removes the test output file if it exists.
      */
     private void removeTestFile()



Mime
View raw message