commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r220277 - in /jakarta/commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/AbstractFileConfiguration.java test/org/apache/commons/configuration/TestFileConfiguration.java
Date Fri, 22 Jul 2005 09:22:36 GMT
Author: oheger
Date: Fri Jul 22 02:22:36 2005
New Revision: 220277

URL: http://svn.apache.org/viewcvs?rev=220277&view=rev
Log:
Fixed NPE in AbstractFileConfiguration.getFile()

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

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=220277&r1=220276&r2=220277&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
Fri Jul 22 02:22:36 2005
@@ -530,11 +530,25 @@
      * URL with a protocol different than "file", the return value
      * will not point to a valid file object.
      * 
-     * @return the file where the configuration is stored
+     * @return the file where the configuration is stored; this can be <b>null</b>
      */
     public File getFile()
     {
-        return ConfigurationUtils.getFile(getBasePath(), getFileName());
+        if (getFileName() == null)
+        {
+            return null;
+        }
+        else
+        {
+            if (sourceURL != null)
+            {
+                return ConfigurationUtils.fileFromURL(sourceURL);
+            }
+            else
+            {
+                return ConfigurationUtils.getFile(getBasePath(), getFileName());
+            }
+        }
     }
 
     /**

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=220277&r1=220276&r2=220277&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
Fri Jul 22 02:22:36 2005
@@ -355,4 +355,18 @@
             }
         }
     }
+    
+    /**
+     * Tests the getFile() method.
+     */
+    public void testGetFile() throws ConfigurationException
+    {
+        FileConfiguration config = new PropertiesConfiguration();
+        assertNull(config.getFile());
+        File file = new File("conf/test.properties").getAbsoluteFile();
+        config.setFile(file);
+        assertEquals(file, config.getFile());
+        config.load();
+        assertEquals(file, config.getFile());
+    }
 }



---------------------------------------------------------------------
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