28-May-2022 - 6.46.0

The PMD team is pleased to announce PMD 6.46.0.

This is a minor release.

New and noteworthy

CLI improvements

The PMD CLI now allows repeating the --dir (-d) and --rulesets (-R) options, as well as providing several space-separated arguments to either of them. For instance:

pmd -d src/main/java src/test/java -R rset1.xml -R rset2.xml

This also allows globs to be used on the CLI if your shell supports shell expansion. For instance, the above can be written

pmd -d src/*/java -R rset*.xml

Please use theses new forms instead of using comma-separated lists as argument to these options.

C# Improvements

When executing CPD on C# sources, the option --ignore-annotations is now supported as well. It ignores C# attributes when detecting duplicated code. This option can also be enabled via the CPD GUI. See #3974 for details.

New Rules

This release ships with 2 new Java rules.

  • EmptyControlStatement reports many instances of empty things, e.g. control statements whose body is empty, as well as empty initializers.

    EmptyControlStatement also works for empty for and do loops, while there were previously no corresponding rules.

    This new rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt.

<rule ref="category/java/codestyle.xml/EmptyControlStatement"/>

The rule is part of the quickstart.xml ruleset.

  • UnnecessarySemicolon reports semicolons that are unnecessary (so called “empty statements” and “empty declarations”).

    This new rule replaces the rule EmptyStatementNotInLoop.

<rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/>

The rule is part of the quickstart.xml ruleset.

Deprecated Rules

Fixed Issues

  • cli
    • #1445: [core] Allow CLI to take globs as parameters
  • core
    • #2352: [core] Deprecate <lang>-<ruleset> hyphen notation for ruleset references
    • #3787: [core] Internalize some methods in Ant Formatter
    • #3835: [core] Deprecate system properties of CPDCommandLineInterface
    • #3942: [core] common-io path traversal vulnerability (CVE-2021-29425)
  • cs (c#)
    • #3974: [cs] Add option to ignore C# attributes (annotations)
  • go
    • #2752: [go] Error parsing unicode values
  • html
    • #3955: [html] Improvements for handling text and comment nodes
    • #3978: [html] Add additional file extensions htm, xhtml, xht, shtml
  • java
    • #3423: [java] Error processing identifiers with Unicode
  • java-bestpractices
    • #3954: [java] NPE in UseCollectionIsEmptyRule when .size() is called in a record
  • java-design
    • #3874: [java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito)
  • java-errorprone
    • #3096: [java] EmptyStatementNotInLoop FP in 6.30.0 with IfStatement
  • java-performance
    • #3379: [java] UseArraysAsList must ignore primitive arrays
    • #3965: [java] UseArraysAsList false positive with non-trivial loops
  • javascript
    • #2605: [js] Support unicode characters
    • #3948: [js] Invalid operator error for method property in object literal
  • python
    • #2604: [python] Support unicode identifiers

API Changes

Deprecated ruleset references

Ruleset references with the following formats are now deprecated and will produce a warning when used on the CLI or in a ruleset XML file:

  • <lang-name>-<ruleset-name>, eg java-basic, which resolves to rulesets/java/basic.xml
  • the internal release number, eg 600, which resolves to rulesets/releases/600.xml

Use the explicit forms of these references to be compatible with PMD 7.

Deprecated API

  • toString is now deprecated. The format of this method will remain the same until PMD 7. The deprecation is intended to steer users away from relying on this format, as it may be changed in PMD 7.
  • getInputPaths and setInputPaths are now deprecated. A new set of methods have been added, which use lists and do not rely on comma splitting.

Internal API

Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You’ll also get a deprecation warning.

External Contributions

  • #3961: [java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - @flyhard
  • #3964: [java] Fix #3874 - ImmutableField: fix mockito/spring false positives - @lukelukes
  • #3974: [cs] Add option to ignore C# attributes (annotations) - @maikelsteneker


  • 92 commits
  • 30 closed tickets & PRs
  • Days since last release: 28