Skip to content

Commit

Permalink
Ignore NoSuchFileException in TempDir cleanup (#3667)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gilday authored Apr 16, 2024
1 parent 062214f commit 6dbc84e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ repository on GitHub.
*** The same applies to other types of test methods (`@TestFactory`,
`@ParameterizedTest`, etc.) as well as lifecycle methods (`@BeforeAll`,
`@AfterAll`, `@BeforeEach`, and `@AfterEach`).
* `TempDir` suppresses `NoSuchFileException` when deleting files that may have been deleted
by another thread or process.

[[release-notes-5.11.0-M1-junit-jupiter-deprecations-and-breaking-changes]]
==== Deprecations and Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
if (exc instanceof NoSuchFileException) {
return CONTINUE;
}
// IOException includes `AccessDeniedException` thrown by non-readable or non-executable flags
resetPermissionsAndTryToDeleteAgain(file, exc);
return CONTINUE;
Expand Down

0 comments on commit 6dbc84e

Please sign in to comment.