Skip to content

Commit 6dbc84e

Browse files
authored
Ignore NoSuchFileException in TempDir cleanup (#3667)
While walking the temp directory, the file walker may fail to visit a file that has been removed by another thread or process. In this case, JUnit should ignore the NoSuchFileException, because there's nothing to clean up.
1 parent 062214f commit 6dbc84e

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M1.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ repository on GitHub.
7272
*** The same applies to other types of test methods (`@TestFactory`,
7373
`@ParameterizedTest`, etc.) as well as lifecycle methods (`@BeforeAll`,
7474
`@AfterAll`, `@BeforeEach`, and `@AfterEach`).
75+
* `TempDir` suppresses `NoSuchFileException` when deleting files that may have been deleted
76+
by another thread or process.
7577

7678
[[release-notes-5.11.0-M1-junit-jupiter-deprecations-and-breaking-changes]]
7779
==== Deprecations and Breaking Changes

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
338338

339339
@Override
340340
public FileVisitResult visitFileFailed(Path file, IOException exc) {
341+
if (exc instanceof NoSuchFileException) {
342+
return CONTINUE;
343+
}
341344
// IOException includes `AccessDeniedException` thrown by non-readable or non-executable flags
342345
resetPermissionsAndTryToDeleteAgain(file, exc);
343346
return CONTINUE;

0 commit comments

Comments
 (0)