Skip to content

Commit

Permalink
Handle file deletion gracefully in JarFileUtils
Browse files Browse the repository at this point in the history
JarFileUtils.delete(File f) throw actual exception (instead of FileNotFound) when file cannot be deleted #2825
  • Loading branch information
speedythesnail committed Nov 7, 2022
1 parent b1f5883 commit ae496a3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,3 +26,4 @@ z_build
.DS_Store
outputDir/
**/Version.java
**/bin/
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2825: JarFileUtils.delete(File f) throw actual exception (instead of FileNotFound) when file cannot be deleted (Steven Jubb)
Fixed: GITHUB2818: Add configuration key for callback discrepancy behavior (Krishnan Mahadevan)
Fixed: GITHUB-2819: Ability to retry a data provider in case of failures (Krishnan Mahadevan)
Fixed: GITHUB-2308: StringIndexOutOfBoundsException in findClassesInPackage - Surefire/Maven - JDK 11 fails (Krishnan Mahadevan)
Expand Down
3 changes: 1 addition & 2 deletions testng-core/src/main/java/org/testng/JarFileUtils.java
@@ -1,7 +1,6 @@
package org.testng;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -112,7 +111,7 @@ private void delete(File f) throws IOException {
if (f.isDirectory()) {
for (File c : Objects.requireNonNull(f.listFiles())) delete(c);
}
if (!f.delete()) throw new FileNotFoundException("Failed to delete file: " + f);
Files.deleteIfExists(f.toPath());
}

private boolean matchesXmlPathInJar(JarEntry je) {
Expand Down

0 comments on commit ae496a3

Please sign in to comment.