From ae496a3daff8dd200edbe236ed6eb5e081241331 Mon Sep 17 00:00:00 2001 From: speedythesnail <54776159+speedythesnail@users.noreply.github.com> Date: Sun, 6 Nov 2022 23:08:02 -0500 Subject: [PATCH] Handle file deletion gracefully in JarFileUtils JarFileUtils.delete(File f) throw actual exception (instead of FileNotFound) when file cannot be deleted #2825 --- .gitignore | 1 + CHANGES.txt | 1 + testng-core/src/main/java/org/testng/JarFileUtils.java | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e16cab7532..bf9094b06a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ z_build .DS_Store outputDir/ **/Version.java +**/bin/ diff --git a/CHANGES.txt b/CHANGES.txt index ed88ccd4ef..feb35c0a81 100644 --- a/CHANGES.txt +++ b/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) diff --git a/testng-core/src/main/java/org/testng/JarFileUtils.java b/testng-core/src/main/java/org/testng/JarFileUtils.java index ff0cf32b4f..176881bc2f 100644 --- a/testng-core/src/main/java/org/testng/JarFileUtils.java +++ b/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; @@ -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) {