[
https://issues.apache.org/jira/browse/IO-280?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sebb updated IO-280:
Description:
FileUtils.openOutputStream() has the following code:
{code}
File parent = file.getParentFile();
if (parent != null parent.exists() == false) {
if (parent.mkdirs() == false) {
throw new IOException(File ' + file + ' could not be created);
}
}
{code}
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:
{code}
File parent = file.getParentFile();
if (parent != null !parent.mkdirs() !parent.isDirectory()) {
throw new IOException(Directory ' + parent + ' could not be created);
// note changed text
}
{code}
Similarly elsewhere in the class where mkdirs() is used.
was:
FileUtils.openOutputStream() has the following code:
{code}
File parent = file.getParentFile();
if (parent != null parent.exists() == false) {
if (parent.mkdirs() == false) {
throw new IOException(File ' + file + ' could not be created);
}
}
{code}
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:
{code}
File parent = file.getParentFile();
if (parent != null !parent.mkdirs() !parent.isDirectory()) {
throw new IOException(Directory ' + parent + ' could not be
created); // note changed text
}
}
{code}
Similarly elsewhere in the class where mkdirs() is used.
Dubious use of mkdirs() return code
---
Key: IO-280
URL: https://issues.apache.org/jira/browse/IO-280
Project: Commons IO
Issue Type: Bug
Reporter: Sebb
Priority: Minor
Fix For: 2.1
FileUtils.openOutputStream() has the following code:
{code}
File parent = file.getParentFile();
if (parent != null parent.exists() == false) {
if (parent.mkdirs() == false) {
throw new IOException(File ' + file + ' could not be created);
}
}
{code}
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:
{code}
File parent = file.getParentFile();
if (parent != null !parent.mkdirs() !parent.isDirectory()) {
throw new IOException(Directory ' + parent + ' could not be created);
// note changed text
}
{code}
Similarly elsewhere in the class where mkdirs() is used.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira