commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] Created: (IO-112) NPE in FileUtils.openOutputStream(File) when file has no parent in path.
Date Sun, 04 Feb 2007 22:13:05 GMT
NPE in FileUtils.openOutputStream(File) when file has no parent in path.
------------------------------------------------------------------------

                 Key: IO-112
                 URL: https://issues.apache.org/jira/browse/IO-112
             Project: Commons IO
          Issue Type: Bug
          Components: Utilities
    Affects Versions: 1.3
         Environment: Sun Java 1.4.2_13. 
Windows XP SP2 + current patches.
Eclipse 3.3M4.
            Reporter: Gary Gregory
         Assigned To: Gary Gregory
             Fix For: 1.4


-----Original Message-----
From: deng xinzi [mailto:xinzi6388@gmail.com] 
Sent: Sunday, February 04, 2007 6:19 AM
To: commons-dev@jakarta.apache.org
Subject: [bug]commons-io 1.3 FileUtils.openOutputStream(File file) NullPointException

FileUtils.openOutputStream(File file)
When the file = new File( "abc.txt" );
There will be a NullPointerException throw.
Cause
file = new File("abc.txt")
file.getParentFile() returns null.

So I suggest adding the null check code like this.

            File parent = file.getParentFile();
            if( parent != null ) {   // ADD THIS!!!
              if (parent.exists() == false) {
                if (parent.mkdirs() == false) {
                    throw new IOException("File '" + file + "' could not be
created");
                }
              }
            }


                                       Xinzi ...


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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