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 2022/08/01 23:03:03 UTC
[commons-fileupload] branch master updated: Fix Checkstyle
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push:
new a337d6e Fix Checkstyle
a337d6e is described below
commit a337d6ea804783314cf5870646e38e6323670b63
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 1 19:02:57 2022 -0400
Fix Checkstyle
---
.../commons/fileupload2/disk/DiskFileItem.java | 30 +++++-----------------
1 file changed, 7 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
index 923daa6..2c384ec 100644
--- a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
@@ -355,7 +355,7 @@ public class DiskFileItem
}
return new String(rawData, charset);
} catch (final IOException e) {
- return new String(new byte[0]);
+ return "";
}
}
@@ -413,18 +413,18 @@ public class DiskFileItem
}
/**
- * Deletes the underlying storage for a file item, including deleting any
- * associated temporary disk file. Although this storage will be deleted
- * automatically when the {@code FileItem} instance is garbage
- * collected, this method can be used to ensure that this is done at an
- * earlier time, thus preserving system resources.
+ * Deletes the underlying storage for a file item, including deleting any associated temporary disk file.
+ * This method can be used to ensure that this is done at an earlier time, thus preserving system resources.
*/
@Override
public void delete() {
cachedContent = null;
final File outputFile = getStoreLocation();
if (outputFile != null && !isInMemory() && outputFile.exists()) {
- outputFile.delete();
+ if (!outputFile.delete()) {
+ final String desc = "Cannot delete " + outputFile.toString();
+ throw new UncheckedIOException(desc, new IOException(desc));
+ }
}
}
@@ -529,22 +529,6 @@ public class DiskFileItem
// ------------------------------------------------------ Protected methods
- /**
- * Removes the file contents from the temporary storage.
- */
- @Override
- protected void finalize() throws Throwable {
- if (dfos == null || dfos.isInMemory()) {
- return;
- }
- final File outputFile = dfos.getFile();
-
- if (outputFile != null && outputFile.exists()) {
- outputFile.delete();
- }
- super.finalize();
- }
-
/**
* Creates and returns a {@link java.io.File File} representing a uniquely
* named temporary file in the configured repository path. The lifetime of