This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new acf67a8495 Update internal fork of Apache Commons FileUpload
acf67a8495 is described below
commit acf67a8495db6219f7547b36b92a49afb3df7e59
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Nov 29 15:20:39 2022 +0000
Update internal fork of Apache Commons FileUpload
---
MERGE.txt | 2 +-
.../util/http/fileupload/FileUploadBase.java | 2 +-
.../util/http/fileupload/MultipartStream.java | 2 +-
.../util/http/fileupload/RequestContext.java | 2 +-
.../util/http/fileupload/disk/DiskFileItem.java | 43 +++++++---------------
.../http/fileupload/disk/DiskFileItemFactory.java | 2 +-
.../http/fileupload/util/FileItemHeadersImpl.java | 3 +-
webapps/docs/changelog.xml | 4 ++
8 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/MERGE.txt b/MERGE.txt
index c3db5d047f..5a74e6264b 100644
--- a/MERGE.txt
+++ b/MERGE.txt
@@ -54,7 +54,7 @@ Unused code is removed
Sub-tree:
src/main/java/org/apache/commons/fileupload2
The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
-33d2d79230bb851642435821b380904d24752ee1 (2021-09-01)
+aa8eff6f04c939fd99834360415b1ddb2f637cb1 (2022-11-29)
Note: Tomcat's copy of fileupload also includes classes copied manually from
Commons IO.
diff --git a/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
b/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
index 45c4fb93c0..acc4aa307f 100644
--- a/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
+++ b/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
@@ -309,7 +309,7 @@ public abstract class FileUploadBase {
if (boundaryStr == null) {
return null;
}
- byte[] boundary;
+ final byte[] boundary;
boundary = boundaryStr.getBytes(StandardCharsets.ISO_8859_1);
return boundary;
}
diff --git a/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
b/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
index d38eb379d5..179673654c 100644
--- a/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
+++ b/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
@@ -401,7 +401,7 @@ public class MultipartStream {
public boolean readBoundary()
throws FileUploadIOException, MalformedStreamException {
final byte[] marker = new byte[2];
- boolean nextChunk;
+ final boolean nextChunk;
head += boundaryLength;
try {
diff --git a/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
b/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
index 8fb222ce2b..9c00856032 100644
--- a/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
+++ b/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
@@ -24,7 +24,7 @@ import java.io.InputStream;
* interface should be implemented for each type of request that may be
* handled by FileUpload, such as servlets and portlets.</p>
*
- * @since FileUpload 1.1
+ * @since 1.1
*/
public interface RequestContext {
diff --git a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
index 55273b51d4..f748680f86 100644
--- a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
+++ b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
@@ -56,7 +56,7 @@ import org.apache.tomcat.util.http.fileupload.util.Streams;
* <p>Temporary files, which are created for file items, should be
* deleted later on.</p>
*
- * @since FileUpload 1.1
+ * @since 1.1
*/
public class DiskFileItem
implements FileItem {
@@ -299,11 +299,11 @@ public class DiskFileItem
return cachedContent != null ? cachedContent.clone() : new byte[0];
}
- byte[] fileData = new byte[(int) getSize()];
+ final byte[] fileData = new byte[(int) getSize()];
try (InputStream fis = Files.newInputStream(dfos.getFile().toPath())) {
IOUtils.readFully(fis, fileData);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new UncheckedIOException(e);
}
return fileData;
@@ -339,14 +339,14 @@ public class DiskFileItem
@Override
public String getString() {
try {
- byte[] rawData = get();
+ final byte[] rawData = get();
String charset = getCharSet();
if (charset == null) {
charset = defaultCharset;
}
return new String(rawData, charset);
} catch (final IOException e) {
- return new String(new byte[0]);
+ return "";
}
}
@@ -375,7 +375,7 @@ public class DiskFileItem
if (isInMemory()) {
try (OutputStream fout = Files.newOutputStream(file.toPath())) {
fout.write(get());
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new IOException("Unexpected output data");
}
} else {
@@ -416,18 +416,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));
+ }
}
}
@@ -437,7 +437,7 @@ public class DiskFileItem
*
* @return The name of the form field.
*
- * @see #setFieldName(java.lang.String)
+ * @see #setFieldName(String)
*
*/
@Override
@@ -532,23 +532,6 @@ public class DiskFileItem
// ------------------------------------------------------ Protected methods
- /**
- * Removes the file contents from the temporary storage.
- */
- @SuppressWarnings("deprecation") // Need Commons FileUpload to address this
- @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
diff --git
a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java
b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java
index 67a2ed17bc..5d9a82417b 100644
--- a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java
+++ b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java
@@ -54,7 +54,7 @@ import org.apache.tomcat.util.http.fileupload.FileItemFactory;
* <p>Temporary files, which are created for file items, should be
* deleted later on.</p>
*
- * @since FileUpload 1.1
+ * @since 1.1
*/
public class DiskFileItemFactory implements FileItemFactory {
diff --git
a/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
b/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
index ebf1fec3eb..47c436fba1 100644
--- a/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
+++ b/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
@@ -87,7 +87,8 @@ public class FileItemHeadersImpl implements FileItemHeaders,
Serializable {
*/
public synchronized void addHeader(final String name, final String value) {
final String nameLower = name.toLowerCase(Locale.ENGLISH);
- List<String> headerValueList =
headerNameToValueListMap.computeIfAbsent(nameLower, k -> new ArrayList<>());
+ final List<String> headerValueList = headerNameToValueListMap.
+ computeIfAbsent(nameLower, k -> new ArrayList<>());
headerValueList.add(value);
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0d518c7909..7a89a36cf8 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -172,6 +172,10 @@
<update>
Update to Commons Daemon 1.3.3. (markt)
</update>
+ <update>
+ Update the internal fork of Apache Commons FileUpload to aa8eff6
+ (2022-11-29, 2.0-SNAPSHOT). (markt)
+ </update>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]