Skip to content

Commit c4178aa

Browse files
committed
chore: Update PMD
This patch bumps the Maven PMD plugin from 3.13.0 -> 3.16.0 as well as the version of PMD used by the Maven PMD plugin, from 6.28.0 -> 6.43.0. This matches the version of PMD used by the latest stable pmd-eclipse-plugin (4.32.0). This patch removes deprecated rules from the PMD ruleset, and updates the source where necessary to account for new rules.
1 parent 99a5f96 commit c4178aa

File tree

13 files changed

+148
-36
lines changed

13 files changed

+148
-36
lines changed

SuppressWarnings.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ make it harder to follow the logic due to the additional indirection.
3434
// See SuppressWarnings.md#complexity
3535
"PMD.CyclomaticComplexity",
3636
"PMD.NPathComplexity",
37+
"PMD.CognitiveComplexity",
3738
"java:S3776"
3839
})
3940
```
@@ -85,4 +86,11 @@ couldn't find a PMD parameter that allows me to change the regex.
8586
```java
8687
@SuppressWarnings({"PMD.GenericsNaming", "java:S119"}) // See SuppressWarnings.md
8788
```
89+
## Duplicate Literals
8890

91+
Though it is generally good to avoid duplicate literals, inline literals in
92+
unit tests often makes them much easier to read.
93+
94+
```java
95+
@SuppressWarnings("PMD.AvoidDuplicateLiterals") // See SuppressWarnings.md
96+
```

config/pmd-ruleset.xml

Lines changed: 86 additions & 20 deletions
Large diffs are not rendered by default.

module/jsonurl-core/src/main/java/org/jsonurl/Limits.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void setMaxParseValues(int maxParseValues) {
8282

8383
@Override
8484
public int hashCode() {
85-
final int prime = 31;
85+
final int prime = 31; // NOPMD - AvoidFinalLocalVariable
8686
int result = 1;
8787
result = prime * result + (int) (maxParseChars ^ (maxParseChars >>> 32));
8888
result = prime * result + maxParseDepth;

module/jsonurl-core/src/main/java/org/jsonurl/ParseException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,23 @@ protected String typeDescription() {
120120
@Override
121121
@SuppressWarnings("java:S1117") // See SuppressWarnings.md
122122
public String toString() {
123-
StringBuilder buf = new StringBuilder(64);
123+
final StringBuilder buf = new StringBuilder(64);
124124

125125
buf.append("jsonurl ")
126126
.append(typeDescription())
127127
.append(": ")
128128
.append(getMessage());
129129

130-
int line = getLineNumber();
130+
final int line = getLineNumber();
131131
if (line > -1) {
132132
buf.append(" at ").append(line);
133133

134-
int col = getColumn();
134+
final int col = getColumn();
135135
if (col > -1) {
136136
buf.append(':').append(col);
137137
}
138138
} else {
139-
long off = getOffset();
139+
final long off = getOffset();
140140
if (off > -1) {
141141
buf.append(" at ").append(off);
142142
}

module/jsonurl-core/src/main/java/org/jsonurl/text/JsonUrlTextAppender.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ private static boolean contains(
462462
// See SuppressWarnings.md#complexity
463463
"PMD.CyclomaticComplexity",
464464
"PMD.NPathComplexity",
465+
"PMD.CognitiveComplexity",
465466
"java:S3776"
466467
})
467468
private static <T extends Appendable> boolean appendLiteral(

module/jsonurl-core/src/main/java/org/jsonurl/text/NumberCoercionMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@
5555
* <td>{@link java.lang.Double Double}</td></tr>
5656
* </table>
5757
*/
58-
final class NumberCoercionMap { //NOPMD - ClassNamingConventions
58+
final class NumberCoercionMap {
5959

6060
/**
6161
* Static map of input type to coerced type.
6262
*/
63+
// access is guaranteed to be sync inside the static initializer, and it
64+
// is read-only thereafter. There's no need for the additional overhead
65+
// of ConcurrentHashMap here.
66+
@SuppressWarnings("PMD.UseConcurrentHashMap")
6367
private static final Map<
6468
Class<? extends Number>,
6569
Class<? extends Number>> MAP = new HashMap<>();

module/jsonurl-core/src/main/java/org/jsonurl/util/PercentCodec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static int decode(CharIterator text) throws IOException {
7070
// See SuppressWarnings.md#complexity
7171
"PMD.CyclomaticComplexity",
7272
"PMD.NPathComplexity",
73+
"PMD.CognitiveComplexity",
7374
"java:S3776",
7475

7576
// once you understand UTF-8 it's far more readable with the

module/jsonurl-core/src/test/java/org/jsonurl/stream/JsonUrlIteratorTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
* @author David MacCormack
4545
* @since 2019-10-01
4646
*/
47-
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
47+
@SuppressWarnings({
48+
"PMD.AvoidDuplicateLiterals",
49+
"PMD.ExcessiveClassLength" // yup, I have a lot of tests
50+
})
4851
class JsonUrlIteratorTest {
4952

5053
/** empty string. */
@@ -253,7 +256,10 @@ void testAQF(EventTest test) throws IOException {
253256
testEvents(test, jui);
254257
}
255258

256-
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
259+
@SuppressWarnings({
260+
"checkstyle:AbbreviationAsWordInName",
261+
"PMD.ExcessiveMethodLength" // yup, I have a lot of tests
262+
})
257263
static Stream<EventTest> testAQF() {
258264
return Stream.concat(COMMON_TESTS.parallelStream(),
259265
Arrays.stream(new EventTest[] {
@@ -428,7 +434,10 @@ void testNotAQF(EventTest test) throws IOException {
428434
testEvents(test, jui);
429435
}
430436

431-
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
437+
@SuppressWarnings({
438+
"checkstyle:AbbreviationAsWordInName",
439+
"PMD.ExcessiveMethodLength" // yup, I have a lot of tests
440+
})
432441
static Stream<EventTest> testNotAQF() {
433442
return Stream.concat(COMMON_TESTS.parallelStream(),
434443
Arrays.stream(new EventTest[] {

module/jsonurl-factory/src/main/java/org/jsonurl/j2se/JsonUrlWriter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public static <R> boolean write(
7676
@SuppressWarnings({
7777
// See SuppressWarnings.md#complexity
7878
"PMD.CyclomaticComplexity",
79+
"PMD.CognitiveComplexity",
7980
"PMD.NPathComplexity",
8081
"java:S3776"
8182
})
@@ -374,6 +375,7 @@ public static <R> boolean write(
374375
@SuppressWarnings({
375376
// See SuppressWarnings.md
376377
"PMD.CyclomaticComplexity",
378+
"PMD.CognitiveComplexity",
377379
"PMD.AvoidReassigningLoopVariables",
378380
"java:S127"
379381
})

module/jsonurl-factory/src/test/java/org/jsonurl/factory/AbstractJsonApiWriteTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ void testInline(String text, V obj) throws Exception {
121121
V obj2 = vfp.parse(jsonUriText);
122122

123123
String jsonText = valueToString(obj2);
124-
assertEquals(text, jsonText);
124+
assertEquals(text, jsonText, text);
125125
}
126126
}

0 commit comments

Comments
 (0)