-
Bug
-
Resolution: Fixed
-
P3
-
10
-
b17
We have several intermittent issues on Windows relative to FileUtils
see
https://bugs.openjdk.java.net/browse/JDK-8177357 and https://bugs.openjdk.java.net/browse/JDK-8169971
My understanding of the root cause is following
When test working directory is cleaned up after a test case there are open file handlers. Perhaps due to McAfee scanner or another software which analyzes files created by test in background.
If so the deleted file just is marked for deletion. It actually exists in the working directory unless all open handlers will be closed. But Files.exists() will return false for such file marked for deletion. And FileUtils relays on the exists() method in waiting loop which checks that file is deleted. We actually should check for absence of the file not for presence.
The following code on Windows prints false in both cases
public static void main(String[] args) throws Exception {
Path tmp = Paths.get("tmp");
Files.createDirectories(tmp);
Path file = tmp.resolve("file.txt");
BufferedWriter bw = Files.newBufferedWriter(file);//save handle to file
Files.delete(file); //mark for deletion on windows
System.out.println("Files.exists(): " + Files.exists(file) );
System.out.println("Files.notExists(): " + Files.notExists(file));
bw.close();
}
What's why we get DirectoryNotEmptyException
see
https://bugs.openjdk.java.net/browse/JDK-8177357 and https://bugs.openjdk.java.net/browse/JDK-8169971
My understanding of the root cause is following
When test working directory is cleaned up after a test case there are open file handlers. Perhaps due to McAfee scanner or another software which analyzes files created by test in background.
If so the deleted file just is marked for deletion. It actually exists in the working directory unless all open handlers will be closed. But Files.exists() will return false for such file marked for deletion. And FileUtils relays on the exists() method in waiting loop which checks that file is deleted. We actually should check for absence of the file not for presence.
The following code on Windows prints false in both cases
public static void main(String[] args) throws Exception {
Path tmp = Paths.get("tmp");
Files.createDirectories(tmp);
Path file = tmp.resolve("file.txt");
BufferedWriter bw = Files.newBufferedWriter(file);//save handle to file
Files.delete(file); //mark for deletion on windows
System.out.println("Files.exists(): " + Files.exists(file) );
System.out.println("Files.notExists(): " + Files.notExists(file));
bw.close();
}
What's why we get DirectoryNotEmptyException
- relates to
-
JDK-8227438 [TESTLIB] Determine if file exists by Files.exists in function FileUtils.deleteFileIfExistsWithRetry
-
- Resolved
-
-
JDK-8181582 java/net/httpclient/RequestBodyTest.java fails intermittently with java.nio.file.AccessDeniedException: RequestBodyTest.tmp
-
- Closed
-