Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
Description
FileUtils.openOutputStream() has the following code:
File parent = file.getParentFile(); if (parent != null && parent.exists() == false) { if (parent.mkdirs() == false) { throw new IOException("File '" + file + "' could not be created"); } }
Now mkdirs() returns true only if the method actually created the directories; it's theoretically possible for the directory to be created in the window between the exists() and mkdirs() invocations. [Indeed the class actually checks for this in the forceMkdir() method]
It would be safer to use:
File parent = file.getParentFile(); if (parent != null && !parent.mkdirs() && !parent.isDirectory()) { throw new IOException("Directory '" + parent + "' could not be created"); // note changed text }
Similarly elsewhere in the class where mkdirs() is used.
Attachments
Issue Links
- relates to
-
JCI-67 Dubious use of mkdirs() return code
- Closed