commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r278773 - in /jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/AbstractFileConfiguration.java src/test/org/apache/commons/configuration/TestFileConfiguration.java xdocs/changes.xml
Date Mon, 05 Sep 2005 15:19:04 GMT
Author: ebourg
Date: Mon Sep  5 08:18:58 2005
New Revision: 278773

URL: http://svn.apache.org/viewcvs?rev=278773&view=rev
Log:
Loading a configuration from a directory now throws an exception (Bug 36488)

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java?rev=278773&r1=278772&r2=278773&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Mon Sep  5 08:18:58 2005
@@ -245,13 +245,21 @@
     {
         if (sourceURL == null)
         {
-            if(StringUtils.isEmpty(getBasePath()))
+            if (StringUtils.isEmpty(getBasePath()))
             {
                 // ensure that we have a valid base path
                 setBasePath(url.toString());
             }
             sourceURL = url;
         }
+
+        // throw an exception if the target URL is a directory
+        File file = ConfigurationUtils.fileFromURL(url);
+        if (file != null && file.isDirectory())
+        {
+            throw new ConfigurationException("Cannot load a configuration from a directory");
+        }
+
         InputStream in = null;
 
         try

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java?rev=278773&r1=278772&r2=278773&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
Mon Sep  5 08:18:58 2005
@@ -413,4 +413,52 @@
             //ok
         }
     }
+
+    /**
+     * Checks that loading a directory instead of a file throws an exception.
+     */
+    public void testLoadDirectory()
+    {
+        PropertiesConfiguration config = new PropertiesConfiguration();
+
+        try
+        {
+            config.load("target");
+            fail("Could load config from a directory!");
+        }
+        catch (ConfigurationException e)
+        {
+            // ok
+        }
+
+        try
+        {
+            config.load(new File("target"));
+            fail("Could load config from a directory!");
+        }
+        catch (ConfigurationException e)
+        {
+            // ok
+        }
+
+        try
+        {
+            new PropertiesConfiguration("target");
+            fail("Could load config from a directory!");
+        }
+        catch (ConfigurationException e)
+        {
+            // ok
+        }
+
+        try
+        {
+            new PropertiesConfiguration(new File("target"));
+            fail("Could load config from a directory!");
+        }
+        catch (ConfigurationException e)
+        {
+            // ok
+        }
+    }
 }

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=278773&r1=278772&r2=278773&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Sep  5 08:18:58 2005
@@ -23,6 +23,10 @@
   <body>
 
     <release version="1.2-dev" date="in SVN">
+      <action dev="ebourg" type="update" issue="36488">
+        Attempting to load a configuration from a directory instead of a file
+        will now throw a ConfigurationException.
+      </action>
       <action dev="oheger" type="update" issue="36447">
         If a multi-valued property was involved in an interpolation operation,
         AbstractConfiguration created a string representation of the list of all



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message