Skip to content

Commit 644870b

Browse files
committed
FileUtils.forceDelete(File) does not chain the exception cause
1 parent 0be5698 commit 644870b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,11 +1420,13 @@ private static void forceDelete(final File file, final boolean strict) throws IO
14201420
final Counters.PathCounters deleteCounters;
14211421
try {
14221422
deleteCounters = PathUtils.delete(file.toPath(), PathUtils.EMPTY_LINK_OPTION_ARRAY, StandardDeleteOption.OVERRIDE_READ_ONLY);
1423-
} catch (final NoSuchFileException ex) {
1423+
} catch (final NoSuchFileException e) {
14241424
// Map NIO to IO exception
1425-
throw new FileNotFoundException("Cannot delete file: " + file);
1426-
} catch (final IOException ex) {
1427-
throw new IOException("Cannot delete file: " + file, ex);
1425+
final FileNotFoundException nioEx = new FileNotFoundException("Cannot delete file: " + file);
1426+
nioEx.initCause(e);
1427+
throw nioEx;
1428+
} catch (final IOException e) {
1429+
throw new IOException("Cannot delete file: " + file, e);
14281430
}
14291431
if (deleteCounters.getFileCounter().get() < 1 && deleteCounters.getDirectoryCounter().get() < 1) {
14301432
// didn't find a file to delete.

0 commit comments

Comments
 (0)