You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2021/05/02 18:03:51 UTC
[commons-fileupload] branch master updated: FILEUPLOAD-327 - Solve
SpotBug warning/errors
This is an automated email from the ASF dual-hosted git repository.
jochen 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 1c732d7 FILEUPLOAD-327 - Solve SpotBug warning/errors
new b27fca2 Merge pull request #79 from arturobernalg/feature/FILEUPLOAD-327
1c732d7 is described below
commit 1c732d7ed34fa025327eeb6a2f3b7a6647d408a7
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sat May 1 19:36:43 2021 +0200
FILEUPLOAD-327 - Solve SpotBug warning/errors
---
spotbugs-exclude-filter.xml | 9 ---------
.../java/org/apache/commons/fileupload2/ParameterParser.java | 2 +-
.../java/org/apache/commons/fileupload2/disk/DiskFileItem.java | 9 ++++-----
3 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/spotbugs-exclude-filter.xml b/spotbugs-exclude-filter.xml
index e680028..1ad2747 100644
--- a/spotbugs-exclude-filter.xml
+++ b/spotbugs-exclude-filter.xml
@@ -33,20 +33,11 @@
<Bug pattern="MS_PKGPROTECT" />
</Match>
<Match>
- <Class name="org.apache.commons.fileupload2.ParameterParser" />
- <Method name="parse" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
<Class name="org.apache.commons.fileupload2.disk.DiskFileItem" />
<Bug pattern="DM_DEFAULT_ENCODING" />
</Match>
<Match>
<Class name="org.apache.commons.fileupload2.disk.DiskFileItem" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.fileupload2.disk.DiskFileItem" />
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
</Match>
<Match>
diff --git a/src/main/java/org/apache/commons/fileupload2/ParameterParser.java b/src/main/java/org/apache/commons/fileupload2/ParameterParser.java
index 929da80..22f2328 100644
--- a/src/main/java/org/apache/commons/fileupload2/ParameterParser.java
+++ b/src/main/java/org/apache/commons/fileupload2/ParameterParser.java
@@ -299,7 +299,7 @@ public class ParameterParser {
return new HashMap<>();
}
final HashMap<String, String> params = new HashMap<>();
- this.chars = charArray;
+ this.chars = charArray.clone();
this.pos = offset;
this.len = length;
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 688ec9b..fd4b0dc 100644
--- a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
@@ -305,7 +305,7 @@ public class DiskFileItem
if (cachedContent == null && dfos != null) {
cachedContent = dfos.getData();
}
- return cachedContent;
+ return cachedContent != null ? cachedContent.clone() : new byte[0];
}
byte[] fileData = new byte[(int) getSize()];
@@ -347,16 +347,15 @@ public class DiskFileItem
*/
@Override
public String getString() {
- byte[] rawdata = new byte[0];
try {
- rawdata = get();
+ byte[] rawData = get();
String charset = getCharSet();
if (charset == null) {
charset = defaultCharset;
}
- return new String(rawdata, charset);
+ return new String(rawData, charset);
} catch (final IOException e) {
- return new String(rawdata);
+ return new String(new byte[0]);
}
}