https://issues.apache.org/bugzilla/show_bug.cgi?id=55290
Bug ID: 55290
Summary: Multithreading - Bug: "failed to create the parent
directory"
Product: Ant
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P2
Component: Core
Assignee: [email protected]
Reporter: [email protected]
Created attachment 30611
--> https://issues.apache.org/bugzilla/attachment.cgi?id=30611&action=edit
patch
The method org.apache.tools.ant.util.ResourceUtils#copyResource is not
threadsafe. It will fail sometimes with the "failed to create the parent
directory" - error message. The problem is the following statement:
if (parent != null && !parent.isDirectory()
&& !destFile.getParentFile().mkdirs()) {
throw new IOException("failed to create the parent directory"
+ " for " + destFile);
}
Assumption: Two threads "A" and "B" are trying to create a new directory "X".
If the thread "B" creates the directory "X" after thread "A" has already
executed parent.isDirectory() but not destFile.getParentFile().mkdirs() then
the execution of destFile.getParentFile().mkdirs() from thread "A" will throw a
new IOException (false)....
Fix:
File parent = destFile.getParentFile();
if (parent != null && !parent.isDirectory()) {
parent.mkdirs();
if (!parent.exists()) {
throw new IOException("failed to create the parent directory for " +
destFile);
}
}
--
You are receiving this mail because:
You are the assignee for the bug.