This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch 1.x in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
commit 064aefe5853708b822761f26a5318f89bbbe17a5 Author: Gary Gregory <[email protected]> AuthorDate: Sun Feb 8 10:07:15 2026 -0500 If DiskFileItem.delete() can't delete the file, it marks it for deletion on JVM exit. --- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2f060268..e7ee9fd2 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -47,6 +47,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix Apache RAT plugin console warnings.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Port to JUnit 5.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.fileupload.util.Closeable now extends java.io.Closeable.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">If DiskFileItem.delete() can't delete the file, it marks it for deletion on JVM exit.</action> <!-- ADD --> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 84 to 96.</action> diff --git a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java index 37e8d87e..12acb3f6 100644 --- a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java +++ b/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java @@ -199,7 +199,9 @@ public class DiskFileItem implements FileItem { clear(); final File outputFile = getStoreLocation(); if (outputFile != null && !isInMemory() && outputFile.exists()) { - outputFile.delete(); + if (!outputFile.delete()) { + outputFile.deleteOnExit(); + } } }
