31 July 2021
The PMD team is pleased to announce PMD 6.37.0.
This is a minor release.
This release of PMD brings support for Java 17. PMD supports JEP 409: Sealed Classes which has been promoted to be a standard language feature of Java 17.
PMD also supports JEP 406: Pattern Matching for switch (Preview) as a preview
language feature. In order to analyze a project with PMD that uses these language features, you’ll need to enable
it via the environment variable PMD_JAVA_OPTS
and select the new language version 17-preview
:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 17-preview ...
Note: Support for Java 15 preview language features have been removed. The version “15-preview” is no longer available.
This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.
This release ships with 3 new Java rules.
PrimitiveWrapperInstantiation
reports usages of primitive wrapper
constructors. They are deprecated since Java 9 and should not be used. <rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" />
The rule is part of the quickstart.xml ruleset.
SimplifiableTestAssertion
suggests rewriting
some test assertions to be more readable. <rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
The rule is part of the quickstart.xml ruleset.
ReturnEmptyCollectionRatherThanNull
suggests returning empty collections / arrays
instead of null. <rule ref="category/java/errorprone.xml/ReturnEmptyCollectionRatherThanNull" />
The rule is part of the quickstart.xml ruleset.
MissingBreakInSwitch
has been renamed to
ImplicitSwitchFallThrough
(category error prone) to better reflect the rule’s
purpose: The rule finds implicit fall-through cases in switch statements, which are most
likely unexpected. The old rule name described only one way how to avoid a fall-through,
namely using break
but continue
, throw
and return
avoid a fall-through
as well. This enables us to improve this rule in the future.SimplifiableTestAssertion
merges
their functionality:
The Java rule ReturnEmptyArrayRatherThanNull
is deprecated and removed from
the quickstart ruleset, as the new rule ReturnEmptyCollectionRatherThanNull
supersedes it.
PrimitiveWrapperInstantiation
merges
their functionality:
UnnecessaryWrapperObjectCreation
is deprecated
with no planned replacement before PMD 7. In it’s current state, the rule is not useful
as it finds only contrived cases of creating a primitive wrapper and unboxing it explicitly
in the same expression. In PMD 7 this and more cases will be covered by a
new rule UnnecessaryBoxing
.InefficientStringBuffering
with RecordsPMD has a new CLI option -force-language
. With that a language can be forced to be used for all input files,
irrespective of filenames. When using this option, the automatic language selection by extension is disabled
and all files are tried to be parsed with the given language. Parsing errors are ignored and unparsable files
are skipped.
This option allows to use the xml language for files, that don’t use xml as extension. See also the examples on PMD CLI reference.
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.
net.sourceforge.pmd.cpd.TokenEntry.State
is considered to be internal API.
It will probably be moved away with PMD 7.