Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2146688 | 6u2 | Xueming Shen | P4 | Resolved | Fixed | b01 |
Name: nt126004 Date: 09/05/2002
FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
ADDITIONAL OPERATING SYSTEMS :
All others probably
A DESCRIPTION OF THE PROBLEM :
File.mkdirs fails to create the entire hierarchy of
directories if another application or thread creates
one of the intervening directories while mkdirs is
running.
An example: We have two threads, A and B.
A calls new File("c:\base\a").mkdirs();
B calls new File("c:\base\b").mkdirs();
Pseudo-trace (follow along in File.mkdirs):
A: if (exists()) // c:\base\a doesn't exist
A: if (mkdir()) // fails to create c:\base\a
A: parent = getParent(); // c:\base
A: new File(parent).mkdirs()
B: if (exists()) // c:\base\b doesn't exist
B: if (mkdir()) // fails to create c:\base\b
B: parent = getParent(); // c:\base
B: new File(parent).mkdirs()
A: if (exists()) // c:\base doesn't exist
A: if (mkdir()) // creates c:\base
A: return true;
B: if (exists()) // c:\base does exist
B: return false;
A: mkdir() // creates c:\base\a and returns true
B: // parent.mkdirs returned false so doesn't create
c:\base\b. Returns false.
I can see no reasonable excuse for thread B's mkdirs to
fail just because someone else happened to create one of
the directories in the desired path.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the sample code
2. Check whether both directories were created
It's timing-dependant so it might not happen every time.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Two directories, c:\base\a and c:\base\b, should be created.
Instead, just one of them gets created.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.io.File;
public class MkdirsBug {
public static void main(String[] args)
{
Thread A = new Thread() {
public void run()
{
new File("c:\\base\\a").mkdirs();
}
};
Thread B = new Thread() {
public void run()
{
new File("c:\\base\\b").mkdirs();
}
};
A.start();
B.start();
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Write your own mkdirs.
(Review ID: 164083)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
ADDITIONAL OPERATING SYSTEMS :
All others probably
A DESCRIPTION OF THE PROBLEM :
File.mkdirs fails to create the entire hierarchy of
directories if another application or thread creates
one of the intervening directories while mkdirs is
running.
An example: We have two threads, A and B.
A calls new File("c:\base\a").mkdirs();
B calls new File("c:\base\b").mkdirs();
Pseudo-trace (follow along in File.mkdirs):
A: if (exists()) // c:\base\a doesn't exist
A: if (mkdir()) // fails to create c:\base\a
A: parent = getParent(); // c:\base
A: new File(parent).mkdirs()
B: if (exists()) // c:\base\b doesn't exist
B: if (mkdir()) // fails to create c:\base\b
B: parent = getParent(); // c:\base
B: new File(parent).mkdirs()
A: if (exists()) // c:\base doesn't exist
A: if (mkdir()) // creates c:\base
A: return true;
B: if (exists()) // c:\base does exist
B: return false;
A: mkdir() // creates c:\base\a and returns true
B: // parent.mkdirs returned false so doesn't create
c:\base\b. Returns false.
I can see no reasonable excuse for thread B's mkdirs to
fail just because someone else happened to create one of
the directories in the desired path.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the sample code
2. Check whether both directories were created
It's timing-dependant so it might not happen every time.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Two directories, c:\base\a and c:\base\b, should be created.
Instead, just one of them gets created.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.io.File;
public class MkdirsBug {
public static void main(String[] args)
{
Thread A = new Thread() {
public void run()
{
new File("c:\\base\\a").mkdirs();
}
};
Thread B = new Thread() {
public void run()
{
new File("c:\\base\\b").mkdirs();
}
};
A.start();
B.start();
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Write your own mkdirs.
(Review ID: 164083)
======================================================================
- backported by
-
JDK-2146688 File.mkdirs() fails due to race condition
- Resolved
- duplicates
-
JDK-6492293 Race condition in File.mkdirs
- Closed
-
JDK-6522814 a race bug in src/share/classes/java/io/File.java
- Closed
- relates to
-
JDK-6413452 DefaultFileManager may throw "could not create parent directories" in concurrent execution
- Closed