Merge branch 'master' into use_addAll

This commit is contained in:
Clément Fournier
2020-08-25 14:50:23 +02:00
43 changed files with 257 additions and 176 deletions

View File

@ -96,6 +96,7 @@ For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designe
* [#2108](https://github.com/pmd/pmd/issues/2108): \[java] \[doc] ImmutableField rule: Description should clarify shallow immutability
* [#2461](https://github.com/pmd/pmd/issues/2461): \[java] ExcessiveParameterListRule must ignore a private constructor
* java-errorprone
* [#2264](https://github.com/pmd/pmd/issues/2264): \[java] SuspiciousEqualsMethodName: Improve description about error-prone overloading of equals()
* [#2410](https://github.com/pmd/pmd/issues/2410): \[java] ProperCloneImplementation not valid for final class
* [#2431](https://github.com/pmd/pmd/issues/2431): \[java] InvalidLogMessageFormatRule throws IndexOutOfBoundsException when only logging exception message
* [#2439](https://github.com/pmd/pmd/issues/2439): \[java] AvoidCatchingThrowable can not detect the case: catch (java.lang.Throwable t)
@ -103,6 +104,7 @@ For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designe
* [#2531](https://github.com/pmd/pmd/issues/2531): \[java] UnnecessaryCaseChange can not detect the case like: foo.equals(bar.toLowerCase())
* [#2647](https://github.com/pmd/pmd/issues/2647): \[java] Deprecate rule DataFlowAnomalyAnalysis
* java-performance
* [#1868](https://github.com/pmd/pmd/issues/1868): \[java] false-positive for SimplifyStartsWith if string is empty
* [#2441](https://github.com/pmd/pmd/issues/2441): \[java] RedundantFieldInitializer can not detect a special case for char initialize: `char foo = '\0';`
* [#2530](https://github.com/pmd/pmd/issues/2530): \[java] StringToString can not detect the case: getStringMethod().toString()
@ -176,6 +178,17 @@ are deprecated as internal API.
* [#2699](https://github.com/pmd/pmd/pull/2699): \[java] ProperCloneImplementation not valid for final class - [Mykhailo Palahuta](https://github.com/Drofff)
* [#2700](https://github.com/pmd/pmd/pull/2700): \[java] Fix OnlyOneReturn code example - [Jan-Lukas Else](https://github.com/jlelse)
* [#2722](https://github.com/pmd/pmd/pull/2722): \[doc] \[java] ImmutableField: extend description, fixes #2108 - [Mateusz Stefanski](https://github.com/mateusz-stefanski)
* [#2723](https://github.com/pmd/pmd/pull/2723): \[doc] \[java] SimplifyStartsWith: update description and example, fixes #1868 - [Mateusz Stefanski](https://github.com/mateusz-stefanski)
* [#2724](https://github.com/pmd/pmd/pull/2724): \[doc] [java] SuspiciousEqualsMethodName: update description, fixes #2264 - [Mateusz Stefanski](https://github.com/mateusz-stefanski)
* [#2725](https://github.com/pmd/pmd/pull/2725): Cleanup: change valueOf to parse when we need primitive return value. - [XenoAmess](https://github.com/XenoAmess)
* [#2726](https://github.com/pmd/pmd/pull/2726): Cleanup: replace StringBuffer with StringBuilder - [XenoAmess](https://github.com/XenoAmess)
* [#2727](https://github.com/pmd/pmd/pull/2727): Cleanup: replace indexOf() < 0 with contains - [XenoAmess](https://github.com/XenoAmess)
* [#2728](https://github.com/pmd/pmd/pull/2728): Cleanup: javadoc issues - [XenoAmess](https://github.com/XenoAmess)
* [#2729](https://github.com/pmd/pmd/pull/2729): Cleanup: use print instead of printf if no format exists - [XenoAmess](https://github.com/XenoAmess)
* [#2730](https://github.com/pmd/pmd/pull/2730): Cleanup: StringBuilder issues - [XenoAmess](https://github.com/XenoAmess)
* [#2731](https://github.com/pmd/pmd/pull/2731): Cleanup: avoid compiling Patterns repeatedly - [XenoAmess](https://github.com/XenoAmess)
* [#2732](https://github.com/pmd/pmd/pull/2732): Cleanup: use StandardCharsets instead of Charset.forName - [XenoAmess](https://github.com/XenoAmess)
* [#2734](https://github.com/pmd/pmd/pull/2734): Cleanup: use try with resources - [XenoAmess](https://github.com/XenoAmess)
{% endtocmaker %}

View File

@ -8,7 +8,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
@ -138,9 +138,9 @@ public class RuleSetFactoryCompatibility {
*/
String determineEncoding(byte[] bytes) {
String firstBytes = new String(bytes, 0, bytes.length > 1024 ? 1024 : bytes.length,
Charset.forName("ISO-8859-1"));
StandardCharsets.ISO_8859_1);
Matcher matcher = ENCODING_PATTERN.matcher(firstBytes);
String encoding = Charset.forName("UTF-8").name();
String encoding = StandardCharsets.UTF_8.name();
if (matcher.find()) {
encoding = matcher.group(1);
}

View File

@ -60,10 +60,10 @@ public final class PMDCommandLineInterface {
public static String buildUsageText(JCommander jcommander) {
StringBuilder usage = new StringBuilder();
String allCommandsDescription = null;
StringBuilder allCommandsDescription = null;
if (jcommander != null && jcommander.getCommands() != null) {
for (String command : jcommander.getCommands().keySet()) {
allCommandsDescription += jcommander.getCommandDescription(command) + PMD.EOL;
allCommandsDescription.append(jcommander.getCommandDescription(command)).append(PMD.EOL);
}
}
@ -143,7 +143,7 @@ public final class PMDCommandLineInterface {
Renderer renderer = RendererFactory.createRenderer(reportName, new Properties());
buf.append(" ").append(reportName).append(": ");
if (!reportName.equals(renderer.getName())) {
buf.append(" Deprecated alias for '" + renderer.getName()).append(PMD.EOL);
buf.append(" Deprecated alias for '").append(renderer.getName()).append(PMD.EOL);
continue;
}
buf.append(renderer.getDescription()).append(PMD.EOL);

View File

@ -33,9 +33,8 @@ public class VSRenderer implements Renderer, CPDRenderer {
for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) {
mark = iterator.next();
writer.append(mark.getFilename())
.append('(').append(String.valueOf(mark.getBeginLine())).append("):")
.append(" Between lines " + mark.getBeginLine() + " and "
+ (mark.getBeginLine() + match.getLineCount()) + PMD.EOL);
.append('(').append(String.valueOf(mark.getBeginLine())).append("):")
.append(" Between lines ").append(String.valueOf(mark.getBeginLine())).append(" and ").append(String.valueOf(mark.getBeginLine() + match.getLineCount())).append(PMD.EOL);
}
}
writer.flush();

View File

@ -131,8 +131,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor {
vnode.getParent().addNumberOfViolation(1);
RuleViolation vio = vnode.getRuleViolation();
classBuf.append("<tr>" + " <td>" + vio.getMethodName() + "</td>" + " <td>" + this.displayRuleViolation(vio)
+ "</td>" + "</tr>");
classBuf.append("<tr>" + " <td>").append(vio.getMethodName()).append("</td>").append(" <td>").append(this.displayRuleViolation(vio)).append("</td>").append("</tr>");
}
private void renderPackage(PackageNode pnode) {

View File

@ -79,7 +79,7 @@ public class ParametricRuleViolation<T extends Node> implements RuleViolation {
protected String expandVariables(String message) {
if (message.indexOf("${") < 0) {
if (!message.contains("${")) {
return message;
}

View File

@ -33,7 +33,7 @@ public final class BooleanProperty extends AbstractSingleValueProperty<Boolean>
*/
@Deprecated
public BooleanProperty(String theName, String theDescription, String defaultBoolStr, float theUIOrder) {
this(theName, theDescription, Boolean.valueOf(defaultBoolStr), theUIOrder, false);
this(theName, theDescription, Boolean.parseBoolean(defaultBoolStr), theUIOrder, false);
}

View File

@ -145,27 +145,38 @@ public class CodeClimateRenderer extends AbstractIncrementingRenderer {
}
private <T> String getBody() {
String result = "## " + rule.getName() + "\\n\\n" + "Since: PMD " + rule.getSince() + "\\n\\n" + "Priority: "
+ rule.getPriority() + "\\n\\n"
+ "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): "
+ Arrays.toString(getCategories()).replaceAll("[\\[\\]]", "") + "\\n\\n"
+ "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): "
+ getRemediationPoints() + "\\n\\n" + cleaned(rule.getDescription());
StringBuilder result = new StringBuilder();
result.append("## ")
.append(rule.getName())
.append("\\n\\n")
.append("Since: PMD ")
.append(rule.getSince())
.append("\\n\\n")
.append("Priority: ")
.append(rule.getPriority())
.append("\\n\\n")
.append("[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): ")
.append(Arrays.toString(getCategories()).replaceAll("[\\[\\]]", ""))
.append("\\n\\n")
.append("[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): ")
.append(getRemediationPoints())
.append("\\n\\n")
.append(cleaned(rule.getDescription()));
if (!rule.getExamples().isEmpty()) {
result += "\\n\\n### Example:\\n\\n";
result.append("\\n\\n### Example:\\n\\n");
for (String snippet : rule.getExamples()) {
String exampleSnippet = snippet.replaceAll("\\n", "\\\\n");
exampleSnippet = exampleSnippet.replaceAll("\\t", "\\\\t");
result += "```java\\n" + exampleSnippet + "\\n``` ";
result.append("```java\\n").append(exampleSnippet).append("\\n``` ");
}
}
if (!rule.getPropertyDescriptors().isEmpty()) {
result += "\\n\\n### [PMD properties](" + PMD_PROPERTIES_URL + ")\\n\\n";
result += "Name | Value | Description\\n";
result += "--- | --- | ---\\n";
result.append("\\n\\n### [PMD properties](").append(PMD_PROPERTIES_URL).append(")\\n\\n");
result.append("Name | Value | Description\\n");
result.append("--- | --- | ---\\n");
for (PropertyDescriptor<?> property : rule.getPropertyDescriptors()) {
String propertyName = property.name().replaceAll("\\_", "\\\\_");
@ -182,10 +193,10 @@ public class CodeClimateRenderer extends AbstractIncrementingRenderer {
}
propertyValue = propertyValue.replaceAll("(\n|\r\n|\r)", "\\\\n");
result += propertyName + " | " + propertyValue + " | " + property.description() + "\\n";
result.append(propertyName).append(" | ").append(propertyValue).append(" | ").append(property.description()).append("\\n");
}
}
return cleaned(result);
return cleaned(result.toString());
}
private String cleaned(String original) {

View File

@ -128,12 +128,13 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
buf.append(" bgcolor=\"lightgrey\"");
}
colorize = !colorize;
buf.append("> " + PMD.EOL);
buf.append("<td align=\"center\">" + violationCount + "</td>" + PMD.EOL);
buf.append("<td width=\"*%\">"
+ renderFileName(rv.getFilename(), rv.getBeginLine())
+ "</td>" + PMD.EOL);
buf.append("<td align=\"center\" width=\"5%\">" + Integer.toString(rv.getBeginLine()) + "</td>" + PMD.EOL);
buf.append("> ").append(PMD.EOL);
buf.append("<td align=\"center\">").append(violationCount).append("</td>").append(PMD.EOL);
buf.append("<td width=\"*%\">")
.append(renderFileName(rv.getFilename(), rv.getBeginLine()))
.append("</td>")
.append(PMD.EOL);
buf.append("<td align=\"center\" width=\"5%\">").append(rv.getBeginLine()).append("</td>").append(PMD.EOL);
String d = StringEscapeUtils.escapeHtml4(rv.getDescription());
@ -141,8 +142,8 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
if (StringUtils.isNotBlank(infoUrl)) {
d = "<a href=\"" + infoUrl + "\">" + d + "</a>";
}
buf.append("<td width=\"*\">" + d + "</td>" + PMD.EOL);
buf.append("</tr>" + PMD.EOL);
buf.append("<td width=\"*\">").append(d).append("</td>").append(PMD.EOL);
buf.append("</tr>").append(PMD.EOL);
writer.write(buf.toString());
violationCount++;
}
@ -173,7 +174,7 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
writer.write("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\"><tr>" + PMD.EOL
+ "<th>File</th><th>Problem</th></tr>" + PMD.EOL);
StringBuffer buf = new StringBuffer(500);
StringBuilder buf = new StringBuilder(500);
boolean colorize = true;
for (Report.ProcessingError pe : errors) {
buf.setLength(0);
@ -182,10 +183,10 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
buf.append(" bgcolor=\"lightgrey\"");
}
colorize = !colorize;
buf.append("> " + PMD.EOL);
buf.append("<td>" + renderFileName(pe.getFile(), -1) + "</td>" + PMD.EOL);
buf.append("<td><pre>" + pe.getDetail() + "</pre></td>" + PMD.EOL);
buf.append("</tr>" + PMD.EOL);
buf.append("> ").append(PMD.EOL);
buf.append("<td>").append(renderFileName(pe.getFile(), -1)).append("</td>").append(PMD.EOL);
buf.append("<td><pre>").append(pe.getDetail()).append("</pre></td>").append(PMD.EOL);
buf.append("</tr>").append(PMD.EOL);
writer.write(buf.toString());
}
writer.write("</table>");
@ -210,15 +211,14 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
buf.append(" bgcolor=\"lightgrey\"");
}
colorize = !colorize;
buf.append("> " + PMD.EOL);
buf.append("> ").append(PMD.EOL);
RuleViolation rv = sv.getRuleViolation();
buf.append("<td align=\"left\">" + renderFileName(rv.getFilename(), rv.getBeginLine()) + "</td>" + PMD.EOL);
buf.append("<td align=\"center\">" + rv.getBeginLine() + "</td>" + PMD.EOL);
buf.append("<td align=\"center\">" + renderRuleName(rv.getRule()) + "</td>" + PMD.EOL);
buf.append("<td align=\"center\">" + (sv.suppressedByNOPMD() ? "NOPMD" : "Annotation") + "</td>" + PMD.EOL);
buf.append("<td align=\"center\">" + (sv.getUserMessage() == null ? "" : sv.getUserMessage()) + "</td>"
+ PMD.EOL);
buf.append("</tr>" + PMD.EOL);
buf.append("<td align=\"left\">").append(renderFileName(rv.getFilename(), rv.getBeginLine())).append("</td>").append(PMD.EOL);
buf.append("<td align=\"center\">").append(rv.getBeginLine()).append("</td>").append(PMD.EOL);
buf.append("<td align=\"center\">").append(renderRuleName(rv.getRule())).append("</td>").append(PMD.EOL);
buf.append("<td align=\"center\">").append(sv.suppressedByNOPMD() ? "NOPMD" : "Annotation").append("</td>").append(PMD.EOL);
buf.append("<td align=\"center\">").append(sv.getUserMessage() == null ? "" : sv.getUserMessage()).append("</td>").append(PMD.EOL);
buf.append("</tr>").append(PMD.EOL);
writer.write(buf.toString());
}
writer.write("</table>");
@ -243,10 +243,10 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
buf.append(" bgcolor=\"lightgrey\"");
}
colorize = !colorize;
buf.append("> " + PMD.EOL);
buf.append("<td>" + renderRuleName(ce.rule()) + "</td>" + PMD.EOL);
buf.append("<td>" + ce.issue() + "</td>" + PMD.EOL);
buf.append("</tr>" + PMD.EOL);
buf.append("> ").append(PMD.EOL);
buf.append("<td>").append(renderRuleName(ce.rule())).append("</td>").append(PMD.EOL);
buf.append("<td>").append(ce.issue()).append("</td>").append(PMD.EOL);
buf.append("</tr>").append(PMD.EOL);
writer.write(buf.toString());
}
writer.write("</table>");

View File

@ -66,7 +66,7 @@ public class IDEAJRenderer extends AbstractIncrementingRenderer {
while (violations.hasNext()) {
buf.setLength(0);
RuleViolation rv = violations.next();
buf.append(rv.getDescription() + PMD.EOL);
buf.append(rv.getDescription()).append(PMD.EOL);
buf.append(" at ").append(getFullyQualifiedClassName(rv.getFilename(), sourcePath)).append(".method(");
buf.append(getSimpleFileName(rv.getFilename())).append(':').append(rv.getBeginLine()).append(')')
.append(PMD.EOL);

View File

@ -125,17 +125,41 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
String nextFile = determineFileName(rv.getFilename());
if (!nextFile.equals(lastFile)) {
lastFile = nextFile;
buf.append(this.yellowBold + "*" + this.colorReset + " file: " + this.whiteBold
+ this.getRelativePath(lastFile) + this.colorReset + PMD.EOL);
buf.append(this.yellowBold)
.append("*")
.append(this.colorReset)
.append(" file: ")
.append(this.whiteBold)
.append(this.getRelativePath(lastFile))
.append(this.colorReset)
.append(PMD.EOL);
}
buf.append(
this.green + " src: " + this.cyan + lastFile.substring(lastFile.lastIndexOf(File.separator) + 1)
+ this.colorReset + ":" + this.cyan + rv.getBeginLine()
+ (rv.getEndLine() == -1 ? "" : ":" + rv.getEndLine()) + this.colorReset + PMD.EOL);
buf.append(this.green + " rule: " + this.colorReset + rv.getRule().getName() + PMD.EOL);
buf.append(this.green + " msg: " + this.colorReset + rv.getDescription() + PMD.EOL);
buf.append(this.green + " code: " + this.colorReset + this.getLine(lastFile, rv.getBeginLine()) + PMD.EOL
+ PMD.EOL);
buf.append(this.green)
.append(" src: ")
.append(this.cyan)
.append(lastFile.substring(lastFile.lastIndexOf(File.separator) + 1))
.append(this.colorReset).append(":")
.append(this.cyan)
.append(rv.getBeginLine())
.append(rv.getEndLine() == -1 ? "" : ":" + rv.getEndLine())
.append(this.colorReset)
.append(PMD.EOL);
buf.append(this.green)
.append(" rule: ")
.append(this.colorReset)
.append(rv.getRule().getName())
.append(PMD.EOL);
buf.append(this.green)
.append(" msg: ")
.append(this.colorReset)
.append(rv.getDescription())
.append(PMD.EOL);
buf.append(this.green)
.append(" code: ")
.append(this.colorReset)
.append(this.getLine(lastFile, rv.getBeginLine()))
.append(PMD.EOL)
.append(PMD.EOL);
writer.write(buf.toString());
}
writer.write(PMD.EOL + PMD.EOL);
@ -155,11 +179,26 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
String nextFile = determineFileName(error.getFile());
if (!nextFile.equals(lastFile)) {
lastFile = nextFile;
buf.append(this.redBold + "*" + this.colorReset + " file: " + this.whiteBold
+ this.getRelativePath(lastFile) + this.colorReset + PMD.EOL);
buf.append(this.redBold)
.append("*")
.append(this.colorReset)
.append(" file: ")
.append(this.whiteBold)
.append(this.getRelativePath(lastFile))
.append(this.colorReset)
.append(PMD.EOL);
}
buf.append(this.green + " err: " + this.cyan + error.getMsg() + this.colorReset + PMD.EOL)
.append(this.red).append(error.getDetail()).append(colorReset).append(PMD.EOL).append(PMD.EOL);
buf.append(this.green)
.append(" err: ")
.append(this.cyan)
.append(error.getMsg())
.append(this.colorReset)
.append(PMD.EOL)
.append(this.red)
.append(error.getDetail())
.append(colorReset)
.append(PMD.EOL)
.append(PMD.EOL);
writer.write(buf.toString());
}
@ -167,9 +206,21 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
buf.setLength(0);
numberOfErrors++;
Report.ConfigurationError error = i.next();
buf.append(this.redBold + "*" + this.colorReset + " rule: " + this.whiteBold
+ error.rule().getName() + this.colorReset + PMD.EOL);
buf.append(this.green + " err: " + this.cyan + error.issue() + this.colorReset + PMD.EOL + PMD.EOL);
buf.append(this.redBold)
.append("*")
.append(this.colorReset)
.append(" rule: ")
.append(this.whiteBold)
.append(error.rule().getName())
.append(this.colorReset)
.append(PMD.EOL);
buf.append(this.green)
.append(" err: ")
.append(this.cyan)
.append(error.issue())
.append(this.colorReset)
.append(PMD.EOL)
.append(PMD.EOL);
writer.write(buf.toString());
}

View File

@ -50,12 +50,12 @@ public class TextPadRenderer extends AbstractIncrementingRenderer {
@Override
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
while (violations.hasNext()) {
RuleViolation rv = violations.next();
buf.setLength(0);
// Filename
buf.append(determineFileName(rv.getFilename()) + "(");
buf.append(determineFileName(rv.getFilename())).append("(");
// Line number
buf.append(Integer.toString(rv.getBeginLine())).append(", ");
// Name of violated rule

View File

@ -68,9 +68,8 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
}
colorize = !colorize;
sb.append("<td width=\"50\" align=\"right\"><font class=body>" + rv.getBeginLine()
+ "&nbsp;&nbsp;&nbsp;</font></td>");
sb.append("<td><font class=body>" + rv.getDescription() + "</font></td>");
sb.append("<td width=\"50\" align=\"right\"><font class=body>").append(rv.getBeginLine()).append("&nbsp;&nbsp;&nbsp;</font></td>");
sb.append("<td><font class=body>").append(rv.getDescription()).append("</font></td>");
sb.append("</tr>");
sb.append(lineSep);
writer.write(sb.toString());
@ -130,7 +129,7 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
private String header() {
StringBuilder sb = new StringBuilder(600).append("<html><head><title>PMD</title></head>")
.append("<style type=\"text/css\">").append("<!--" + PMD.EOL)
.append("<style type=\"text/css\">").append("<!--").append(PMD.EOL)
.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }")
.append(PMD.EOL)
.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }")

View File

@ -88,7 +88,7 @@ public class DBMSMetadata {
/**
* {@link java.sql.Types} value representing the type returned by
* {@link callableStatement}
* {@link #callableStatement}
*
* <b>Currently only java.sql.Types.String and java.sql.Types.Clob are
* supported</b>

View File

@ -131,21 +131,21 @@ public class SourceObject {
LOG.entering(CLASS_NAME, "getSuffixFromType", this);
if (null == type || type.isEmpty()) {
return "";
} else if (type.toUpperCase(Locale.ROOT).indexOf("JAVA") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("JAVA")) {
return ".java";
} else if (type.toUpperCase(Locale.ROOT).indexOf("TRIGGER") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("TRIGGER")) {
return ".trg";
} else if (type.toUpperCase(Locale.ROOT).indexOf("FUNCTION") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("FUNCTION")) {
return ".fnc";
} else if (type.toUpperCase(Locale.ROOT).indexOf("PROCEDURE") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("PROCEDURE")) {
return ".prc";
} else if (type.toUpperCase(Locale.ROOT).indexOf("PACKAGE_BODY") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("PACKAGE_BODY")) {
return ".pkb";
} else if (type.toUpperCase(Locale.ROOT).indexOf("PACKAGE") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("PACKAGE")) {
return ".pks";
} else if (type.toUpperCase(Locale.ROOT).indexOf("TYPE_BODY") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("TYPE_BODY")) {
return ".tpb";
} else if (type.toUpperCase(Locale.ROOT).indexOf("TYPE") >= 0) {
} else if (type.toUpperCase(Locale.ROOT).contains("TYPE")) {
return ".tps";
} else {
return "";

View File

@ -66,7 +66,7 @@ public class DFAPanel extends JComponent implements ListSelectionListener {
return "";
}
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append(kids.get(0).getIndex());
for (int j = 1; j < node.getChildren().size(); j++) {

View File

@ -710,7 +710,7 @@ public class Designer implements ClipboardOwner {
String text;
if (value instanceof Node) {
Node node = (Node) value;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
String name = node.getClass().getName().substring(node.getClass().getName().lastIndexOf('.') + 1);
if (Proxy.isProxyClass(value.getClass())) {
name = value.toString();

View File

@ -38,7 +38,7 @@ public class SimpleNodeSubMenu extends JMenu {
}
private void init() {
StringBuffer buf = new StringBuffer(200);
StringBuilder buf = new StringBuilder(200);
for (Node temp = node; temp != null; temp = temp.getParent()) {
buf.insert(0, "/" + temp.toString());
}

View File

@ -7,7 +7,7 @@ package net.sourceforge.pmd;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
@ -16,8 +16,6 @@ import org.junit.Test;
import net.sourceforge.pmd.util.ResourceLoader;
public class RuleSetFactoryCompatibilityTest {
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
private static final Charset UTF_8 = Charset.forName("UTF-8");
@Test
public void testCorrectOldReference() throws Exception {
@ -48,7 +46,7 @@ public class RuleSetFactoryCompatibilityTest {
rsfc.addFilterRuleMoved("dummy", "notexisting", "basic", "OldDummyBasicMockRule");
rsfc.addFilterRuleRenamed("dummy", "basic", "OldDummyBasicMockRule", "NewNameForDummyBasicMockRule");
InputStream stream = new ByteArrayInputStream(ruleset.getBytes(ISO_8859_1));
InputStream stream = new ByteArrayInputStream(ruleset.getBytes(StandardCharsets.ISO_8859_1));
Reader filtered = rsfc.filterRuleSetFile(stream);
String out = IOUtils.toString(filtered);
@ -90,7 +88,7 @@ public class RuleSetFactoryCompatibilityTest {
RuleSetFactoryCompatibility rsfc = new RuleSetFactoryCompatibility();
rsfc.addFilterRuleMovedAndRenamed("dummy", "oldbasic", "OldDummyBasicMockRule", "basic", "NewNameForDummyBasicMockRule");
InputStream stream = new ByteArrayInputStream(ruleset.getBytes(ISO_8859_1));
InputStream stream = new ByteArrayInputStream(ruleset.getBytes(StandardCharsets.ISO_8859_1));
Reader filtered = rsfc.filterRuleSetFile(stream);
String out = IOUtils.toString(filtered);
@ -112,7 +110,7 @@ public class RuleSetFactoryCompatibilityTest {
+ " <rule ref=\"rulesets/dummy/notexisting.xml/DummyBasicMockRule\" />\n"
+ " <rule ref=\"rulesets/dummy/basic.xml/DeletedRule\" />\n"
+ " <rule ref=\"rulesets/dummy/basic.xml/OldNameOfBasicMockRule\" />\n" + "</ruleset>\n";
InputStream stream = new ByteArrayInputStream(in.getBytes(ISO_8859_1));
InputStream stream = new ByteArrayInputStream(in.getBytes(StandardCharsets.ISO_8859_1));
Reader filtered = rsfc.filterRuleSetFile(stream);
String out = IOUtils.toString(filtered);
@ -136,7 +134,7 @@ public class RuleSetFactoryCompatibilityTest {
+ " xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd\">\n"
+ " <description>Test</description>\n" + "\n" + " <rule ref=\"rulesets/dummy/basic.xml\">\n"
+ " <exclude name=\"AnotherOldNameOfBasicMockRule\"/>\n" + " </rule>\n" + "</ruleset>\n";
InputStream stream = new ByteArrayInputStream(in.getBytes(ISO_8859_1));
InputStream stream = new ByteArrayInputStream(in.getBytes(StandardCharsets.ISO_8859_1));
Reader filtered = rsfc.filterRuleSetFile(stream);
String out = IOUtils.toString(filtered);
@ -150,10 +148,10 @@ public class RuleSetFactoryCompatibilityTest {
String testString;
testString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><x></x>";
Assert.assertEquals("ISO-8859-1", rsfc.determineEncoding(testString.getBytes(ISO_8859_1)));
Assert.assertEquals("ISO-8859-1", rsfc.determineEncoding(testString.getBytes(StandardCharsets.ISO_8859_1)));
testString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x></x>";
Assert.assertEquals("UTF-8", rsfc.determineEncoding(testString.getBytes(ISO_8859_1)));
Assert.assertEquals("UTF-8", rsfc.determineEncoding(testString.getBytes(StandardCharsets.ISO_8859_1)));
}
private RuleSet createRulesetFromString(final String ruleset, RuleSetFactory factory)
@ -161,7 +159,7 @@ public class RuleSetFactoryCompatibilityTest {
return factory.createRuleSet(new RuleSetReferenceId(null) {
@Override
public InputStream getInputStream(ResourceLoader resourceLoader) throws RuleSetNotFoundException {
return new ByteArrayInputStream(ruleset.getBytes(UTF_8));
return new ByteArrayInputStream(ruleset.getBytes(StandardCharsets.UTF_8));
}
});
}

View File

@ -13,7 +13,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@ -1269,11 +1269,7 @@ public class RuleSetFactoryTest {
return new RuleSetReferenceId(null) {
@Override
public InputStream getInputStream(ResourceLoader resourceLoader) throws RuleSetNotFoundException {
try {
return new ByteArrayInputStream(ruleSetXml.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
return null;
}
return new ByteArrayInputStream(ruleSetXml.getBytes(StandardCharsets.UTF_8));
}
};
}

View File

@ -54,10 +54,8 @@ public class FileReporterTest {
}
private String readFile(File file) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
StringBuffer buffer = new StringBuffer();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
StringBuilder buffer = new StringBuilder();
String line = reader.readLine();
while (line != null) {
buffer.append(line);
@ -67,10 +65,6 @@ public class FileReporterTest {
}
}
return buffer.toString();
} finally {
if (reader != null) {
reader.close();
}
}
}

View File

@ -7,6 +7,7 @@ package net.sourceforge.pmd.processor;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -98,7 +99,7 @@ public class MultiThreadProcessorTest {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(data.getBytes("UTF-8"));
return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
}
@Override

View File

@ -279,7 +279,7 @@ public class DBMSMetadataTest {
"testURI=%s,\ngetSchemasList()=%s\n,getSourceCodeTypesList()=%s\n,getSourceCodeNmesList()=%s\n",
testURI, testURI.getSchemasList(), testURI.getSourceCodeTypesList(), testURI.getSourceCodeNamesList());
System.out.printf("sourceObjectList ...\n");
System.out.print("sourceObjectList ...\n");
for (SourceObject sourceObject : sourceObjectList) {
System.out.printf("sourceObject=%s\n", sourceObject);
System.out.printf("sourceCode=[%s]\n", getStringFromReader(instance.getSourceCode(sourceObject)));

View File

@ -39,8 +39,7 @@ public class ZipFileExtractor {
* @throws Exception if any error happens during extraction
*/
public static void extractZipFile(Path zipPath, Path tempDir) throws Exception {
ZipFile zip = new ZipFile(zipPath.toFile());
try {
try (ZipFile zip = new ZipFile(zipPath.toFile())) {
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
@ -57,8 +56,6 @@ public class ZipFileExtractor {
}
}
}
} finally {
zip.close();
}
}
@ -70,15 +67,12 @@ public class ZipFileExtractor {
*/
public static List<String> readZipFile(Path zipPath) throws Exception {
List<String> result = new ArrayList<>();
ZipFile zip = new ZipFile(zipPath.toFile());
try {
try (ZipFile zip = new ZipFile(zipPath.toFile())) {
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
result.add(entry.getName());
}
} finally {
zip.close();
}
return result;
}

View File

@ -8,7 +8,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -297,7 +297,7 @@ public class DeadLinksChecker {
private String fileToString(Path mdFile) {
try (InputStream inputStream = Files.newInputStream(mdFile)) {
return IOUtils.toString(inputStream, Charset.forName("UTF-8"));
return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
} catch (IOException ex) {
throw new RuntimeException("error reading " + mdFile, ex);
}

View File

@ -53,7 +53,6 @@ public abstract class Comment extends AbstractNode {
* of the comment as well as the start marker ({@code //}, {@code /*} or {@code /**}
* and the end markers (<code>&#x2a;/</code>).
*
* @param comment the raw comment
* @return List of lines of the comments
*/
private List<String> multiLinesIn() {

View File

@ -10,18 +10,18 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.sourceforge.pmd.lang.java.ast.JavaQualifiedName;
import net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask;
import net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature;
import net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask;
import net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature;
import net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName;
/**
* Statistics about a class, enum, interface, or annotation. Stores information about the contained members and their
* signatures, and memoizes the results of the class metrics computed on the corresponding node.
*
* <p>This class does not provide methods to operate directly on its nested classes, but only on itself. To operate on a
* nested class, retrieve the correct ClassStats with {@link PackageStats#getClassStats(JavaQualifiedName, boolean)}
* nested class, retrieve the correct ClassStats with {@link PackageStats#getClassStats(JavaTypeQualifiedName, boolean)}
* then use the methods of ClassStats. Note that at this level, entities of the data structure do not manipulate
* QualifiedNames anymore, only Strings.
*

View File

@ -75,7 +75,7 @@ public abstract class AbstractPoorMethodCall extends AbstractJavaRule {
String[] methodNames = methodNames();
for (String element : methodNames) {
if (methodCall.indexOf(element) != -1) {
if (methodCall.contains(element)) {
return true;
}
}

View File

@ -210,7 +210,7 @@ public class JUnitTestsShouldIncludeAssertRule extends AbstractJUnitRule {
Node name = pe.getFirstDescendantOfType(ASTName.class);
if (name != null) {
String img = name.getImage();
if (img.indexOf(".") == -1) {
if (!img.contains(".")) {
return false;
}
String[] tokens = img.split("\\.");

View File

@ -93,7 +93,7 @@ public class GenericClassCounterRule extends AbstractJavaRule {
this.operand = getProperty(OPERAND_DESCRIPTOR);
this.typesMatch = RegexHelper.compilePatternsFromList(getProperty(TYPE_MATCH_DESCRIPTOR));
String thresholdAsString = getProperty(THRESHOLD_DESCRIPTOR);
this.threshold = Integer.valueOf(thresholdAsString);
this.threshold = Integer.parseInt(thresholdAsString);
// Initializing list of match
this.matches = new ArrayList<>();

Some files were not shown because too many files have changed in this diff Show More