commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <ggreg...@seagullsoftware.com>
Subject RE: [bug]commons-io 1.3 FileUtils.openOutputStream(File file) NullPointException
Date Sun, 04 Feb 2007 22:19:18 GMT
Hello Xinzi:

I've created this JIRA ticket to track your issue:

[IO-112] NPE in FileUtils.openOutputStream(File) when file has no parent in path.
http://issues.apache.org/jira/browse/IO-112

I've also committed a fix in SVN. You can rebuild from the SVN sources yourself or wait for
the next nightly build.

Thank you,
Gary

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

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