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 2015/04/18 21:07:47 UTC

svn commit: r1674560 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/io/DefaultFileSystem.java test/java/org/apache/commons/configuration2/io/TestDefaultFileSystem.java

Author: oheger
Date: Sat Apr 18 19:07:47 2015
New Revision: 1674560

URL: http://svn.apache.org/r1674560
Log:
Fix for findbugs warning "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE".

The return value of File.mkdirs() should not be ignored. We now throw an
explicit exception. This also simplifies diagnostics when such an error
occurs.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/io/DefaultFileSystem.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/io/TestDefaultFileSystem.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/io/DefaultFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/io/DefaultFileSystem.java?rev=1674560&r1=1674559&r2=1674560&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/io/DefaultFileSystem.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/io/DefaultFileSystem.java Sat Apr 18 19:07:47 2015
@@ -258,8 +258,9 @@ public class DefaultFileSystem extends F
      * Create the path to the specified file.
      *
      * @param file the target file
+     * @throws ConfigurationException if the path cannot be created
      */
-    private void createPath(File file)
+    private void createPath(File file) throws ConfigurationException
     {
         if (file != null)
         {
@@ -269,7 +270,10 @@ public class DefaultFileSystem extends F
                 File parent = file.getParentFile();
                 if (parent != null && !parent.exists())
                 {
-                    parent.mkdirs();
+                    if (!parent.mkdirs())
+                    {
+                        throw new ConfigurationException("Cannot create path: " + parent);
+                    }
                 }
             }
         }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/io/TestDefaultFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/io/TestDefaultFileSystem.java?rev=1674560&r1=1674559&r2=1674560&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/io/TestDefaultFileSystem.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/io/TestDefaultFileSystem.java Sat Apr 18 19:07:47 2015
@@ -19,6 +19,9 @@ package org.apache.commons.configuration
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
+
+import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.impl.NoOpLog;
@@ -63,4 +66,14 @@ public class TestDefaultFileSystem
         fileSystem.setLogger(log);
         assertSame("Logger not set", log, fileSystem.getLogger());
     }
+
+    /**
+     * Tests that an invalid output path causes an exception to be thrown when creating
+     * an ouput stream.
+     */
+    @Test(expected = ConfigurationException.class)
+    public void testGetOutputStreamInvalidPath() throws ConfigurationException
+    {
+        fileSystem.getOutputStream(new File("this is/<certainly>\\an#invalid#*path!"));
+    }
 }