29 May 2021
The PMD team is pleased to announce PMD 6.35.0.
This is a minor release.
This release ships with 3 new Java rules.
JUnit5TestShouldBePackagePrivateenforces the convention that JUnit 5 tests should have minimal visibility. You can try out this rule like so:
<rule ref="category/java/bestpractices.xml/JUnit5TestShouldBePackagePrivate" />
CognitiveComplexityuses the cognitive complexity metric to find overly complex code. This metric improves on the similar cyclomatic complexity in several ways, for instance, it incentivizes using clearly readable shorthands and idioms. See the rule documentation for more details. You can try out this rule like so:
<rule ref="category/java/design.xml/CognitiveComplexity" />
MutableStaticStatefinds non-private static fields that are not final. These fields break encapsulation since these fields can be modified from anywhere within the program. You can try out this rule like so:
<rule ref="category/java/design.xml/MutableStaticState" />
CompareObjectsWithEqualshas now a new property
typesThatCompareByReference. With that property, you can configure types, that should be whitelisted for comparison by reference. By default,
java.lang.Classare allowed, but you could add custom types here. Additionally comparisons against constants are allowed now. This makes the rule less noisy when two constants are compared. Constants are identified by looking for an all-caps identifier.
The rule “DefaultPackage” assumes that any usage of package-access is accidental, and by doing so, prohibits using a really fundamental and useful feature of the language.
To satisfy the rule, you have to make the member public even if it doesn’t need to, or make it protected,
which muddies your intent even more if you don’t intend the class to be extended, and may be at odds with
other rules like
CommentDefaultAccessModifier should be used instead.
It flags the same thing, but has an escape hatch.
The Java rule
CloneThrowsCloneNotSupportedException has been deprecated without
The rule has no real value as
CloneNotSupportedException is a
checked exception and therefore you need to deal with it while implementing the
clone() method. You either
need to declare the exception or catch it. If you catch it, then subclasses can’t throw it themselves explicitly.
Object.clone() will still throw this exception if the
Cloneable interface is not implemented.
Note, this rule has also been removed from the Quickstart Ruleset (
PMD#doPMDis deprecated. Use
PMD#runis deprecated. Use
ThreadSafeReportListenerand the methods to use them in
addListeners) are deprecated. This functionality will be replaced by another TBD mechanism in PMD 7.