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 af733e8 Enable PMD checks af733e8 is described below commit af733e8632b77b89771dcc55e913ea2dd2e54f87 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon May 1 09:26:12 2023 -0400 Enable PMD checks --- .../org/apache/commons/fileupload2/ParameterParser.java | 16 ++++++++-------- .../apache/commons/fileupload2/disk/DiskFileItem.java | 8 +++----- .../commons/fileupload2/impl/FileItemIteratorImpl.java | 4 ++-- .../commons/fileupload2/util/LimitedInputStream.java | 11 ----------- .../commons/fileupload2/util/mime/MimeUtility.java | 2 +- .../fileupload2/util/mime/QuotedPrintableDecoder.java | 2 +- .../commons/fileupload2/util/mime/RFC2231Utility.java | 4 ++-- pom.xml | 2 +- 8 files changed, 18 insertions(+), 31 deletions(-) diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParameterParser.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParameterParser.java index 64770ef..9a266b1 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParameterParser.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParameterParser.java @@ -80,15 +80,15 @@ public class ParameterParser { */ private String getToken(final boolean quoted) { // Trim leading white spaces - while ((i1 < i2) && (Character.isWhitespace(chars[i1]))) { + while (i1 < i2 && Character.isWhitespace(chars[i1])) { i1++; } // Trim trailing white spaces - while ((i2 > i1) && (Character.isWhitespace(chars[i2 - 1]))) { + while (i2 > i1 && Character.isWhitespace(chars[i2 - 1])) { i2--; } // Strip away quotation marks if necessary - if (quoted && ((i2 - i1) >= 2) && (chars[i1] == '"') && (chars[i2 - 1] == '"')) { + if (quoted && i2 - i1 >= 2 && chars[i1] == '"' && chars[i2 - 1] == '"') { i1++; i2--; } @@ -173,22 +173,22 @@ public class ParameterParser { while (hasChar()) { paramName = parseToken(new char[] { '=', separator }); paramValue = null; - if (hasChar() && (charArray[pos] == '=')) { + if (hasChar() && charArray[pos] == '=') { pos++; // skip '=' paramValue = parseQuotedToken(new char[] { separator }); if (paramValue != null) { try { paramValue = RFC2231Utility.hasEncodedValue(paramName) ? RFC2231Utility.decodeText(paramValue) : MimeUtility.decodeText(paramValue); - } catch (final UnsupportedEncodingException e) { + } catch (final UnsupportedEncodingException ignored) { // let's keep the original value in this case } } } - if (hasChar() && (charArray[pos] == separator)) { + if (hasChar() && charArray[pos] == separator) { pos++; // skip separator } - if ((paramName != null) && !paramName.isEmpty()) { + if (paramName != null && !paramName.isEmpty()) { paramName = RFC2231Utility.stripDelimiter(paramName); if (this.lowerCaseNames) { paramName = paramName.toLowerCase(Locale.ENGLISH); @@ -259,7 +259,7 @@ public class ParameterParser { if (!charEscaped && ch == '"') { quoted = !quoted; } - charEscaped = (!charEscaped && ch == '\\'); + charEscaped = !charEscaped && ch == '\\'; i2++; pos++; diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java index 62c8c03..ce2a2e9 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java @@ -210,11 +210,9 @@ public class DiskFileItem implements FileItem { public void delete() { cachedContent = null; final File outputFile = getStoreLocation(); - if (outputFile != null && !isInMemory() && outputFile.exists()) { - if (!outputFile.delete()) { - final String desc = "Cannot delete " + outputFile.toString(); - throw new UncheckedIOException(desc, new IOException(desc)); - } + if (outputFile != null && !isInMemory() && outputFile.exists() && !outputFile.delete()) { + final String desc = "Cannot delete " + outputFile.toString(); + throw new UncheckedIOException(desc, new IOException(desc)); } } diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java index 17db6ac..74ae1c0 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java @@ -249,7 +249,7 @@ public class FileItemIteratorImpl implements FileItemIterator { protected void init(final AbstractFileUpload fileUploadBase, final RequestContext requestContext) throws FileUploadException, IOException { final String contentType = ctx.getContentType(); - if ((null == contentType) || (!contentType.toLowerCase(Locale.ENGLISH).startsWith(AbstractFileUpload.MULTIPART))) { + if (null == contentType || !contentType.toLowerCase(Locale.ENGLISH).startsWith(AbstractFileUpload.MULTIPART)) { throw new FileUploadContentTypeException(String.format("the request doesn't contain a %s or %s stream, content type header is %s", AbstractFileUpload.MULTIPART_FORM_DATA, AbstractFileUpload.MULTIPART_MIXED, contentType), contentType); } @@ -311,7 +311,7 @@ public class FileItemIteratorImpl implements FileItemIterator { */ @Override public FileItemStream next() throws FileUploadException, IOException { - if (eof || (!itemValid && !hasNext())) { + if (eof || !itemValid && !hasNext()) { throw new NoSuchElementException(); } itemValid = false; diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java index 32553b5..be98950 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java @@ -57,17 +57,6 @@ public abstract class LimitedInputStream extends FilterInputStream { } } - /** - * Closes this input stream and releases any system resources associated with the stream. This method simply performs {@code in.close()}. - * - * @throws IOException if an I/O error occurs. - * @see java.io.FilterInputStream#in - */ - @Override - public void close() throws IOException { - super.close(); - } - /** * Called to indicate, that the input streams limit has been exceeded. * diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java index 63a80c7..79b83bb 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java @@ -153,7 +153,7 @@ public final class MimeUtility { // and get handled as normal text. continue; - } catch (final ParseException e) { + } catch (final ParseException ignored) { // just ignore it, skip to next word } } diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoder.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoder.java index 1aa4ca2..09d227e 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoder.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoder.java @@ -71,7 +71,7 @@ final class QuotedPrintableDecoder { // this is a hex pair we need to convert back to a single byte. final int c1 = hexToBinary(b1); final int c2 = hexToBinary(b2); - out.write((c1 << UPPER_NIBBLE_SHIFT) | c2); + out.write(c1 << UPPER_NIBBLE_SHIFT | c2); // 3 bytes in, one byte out bytesWritten++; } diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java index 4295ac7..e94d007 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java @@ -103,7 +103,7 @@ public final class RFC2231Utility { } final byte b1 = HEX_DECODE[text.charAt(i++) & MASK]; final byte b2 = HEX_DECODE[text.charAt(i++) & MASK]; - out.write((b1 << shift) | b2); + out.write(b1 << shift | b2); } else { out.write((byte) c); } @@ -124,7 +124,7 @@ public final class RFC2231Utility { */ public static boolean hasEncodedValue(final String paramName) { if (paramName != null) { - return paramName.lastIndexOf('*') == (paramName.length() - 1); + return paramName.lastIndexOf('*') == paramName.length() - 1; } return false; } diff --git a/pom.xml b/pom.xml index e0436b4..5054dbe 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ </plugin> </plugins> </pluginManagement> - <defaultGoal>clean verify apache-rat:check checkstyle:check javadoc:javadoc spotbugs:check</defaultGoal> + <defaultGoal>clean verify apache-rat:check checkstyle:check pmd:check javadoc:javadoc spotbugs:check</defaultGoal> </build> <reporting>