You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/03/21 22:17:25 UTC
(commons-fileupload) 01/03: DiskFileItem.delete() and finalize() always ties to delete its backing file
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 391c14aa6a6b88914a0f4a50e5e617465d824f47
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 21 14:56:27 2026 -0700
DiskFileItem.delete() and finalize() always ties to delete its backing
file
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/fileupload/disk/DiskFileItem.java | 10 ++--------
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 672e3778..6a0325c1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,6 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
<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>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">DiskFileItem.delete() and finalize() always ties to delete its backing file.</action>
<!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 84 to 97.</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 12acb3f6..42cfa831 100644
--- a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
@@ -198,7 +198,7 @@ public class DiskFileItem implements FileItem {
public void delete() {
clear();
final File outputFile = getStoreLocation();
- if (outputFile != null && !isInMemory() && outputFile.exists()) {
+ if (outputFile != null && outputFile.exists()) {
if (!outputFile.delete()) {
outputFile.deleteOnExit();
}
@@ -212,13 +212,7 @@ public class DiskFileItem implements FileItem {
*/
@Override
protected void finalize() throws Throwable {
- if (dfos == null || dfos.isInMemory()) {
- return;
- }
- final File outputFile = dfos.getFile();
- if (outputFile != null && outputFile.exists()) {
- outputFile.delete();
- }
+ delete();
super.finalize();
}