Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-112

NPE in FileUtils.openOutputStream(File) when file has no parent in path.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3
    • 1.3.1
    • Utilities
    • None
    • Sun Java 1.4.2_13.
      Windows XP SP2 + current patches.
      Eclipse 3.3M4.

    Description

      ----Original Message----
      From: deng xinzi 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 Unable to render embedded object: File (= null ) { // ADD THIS) not found.!!
      if (parent.exists() == false) {
      if (parent.mkdirs() == false)

      { throw new IOException("File '" + file + "' could not be created"); }

      }
      }

      Xinzi ...

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            ggregory Gary D. Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: