22 March 2024
🎉 After a long time, we’re excited to bring you now the next major version of PMD! 🎉
Since this is a big release, we provide here only a concise version of the release notes. We prepared a separate page with the full Detailed Release Notes for PMD 7.0.0.
🤝🙏 Many thanks to all users and contributors who were testing the release candidates and provided feedback and/or PRs!
✨ PMD 7…
💥 Note: Since PMD 7 is a major release, it is not a drop-in replacement for PMD 6.55.0. A detailed documentation of required changes are available in the Migration Guide for PMD 7.
This section lists the most important changes from the last release candidate. The remaining section describes the complete release notes for 7.0.0.
In order to use PMD 7 with maven-pmd-plugin a new compatibility module has been created. This allows to use PMD 7 by simply adding one additional dependency:
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>${pmdVersion}</version>
</dependency>
It is important to add this dependency as the first in the list, so that maven-pmd-plugin sees the (old) compatible versions of some classes.
This module is available beginning with version 7.0.0-rc4 and will be there at least for the first final version PMD 7 (7.0.0). It’s not decided yet, whether we will keep updating it, after PMD 7 is finally released.
Note: This compatibility module only works for the built-in rules, that are still available in PMD 7. E.g. you need to review your rulesets and look out for deprecated rules and such. See the use case I’m using only built-in rules in the Migration Guide for PMD 7.
As PMD 7 revamped the Java module, if you have custom rules, you need to migrate these rules. See the use case I’m using custom rules in the Migration Guide.
Note: Once the default version of PMD is upgraded to PMD7 in maven-pmd-plugin (see MPMD-379), this compatibility module is no longer needed. The module pmd-compat6 might not be maintained then any further, hence it is already declared as deprecated.
No guarantee is given, that the (deprecated) module pmd-compat6 is being maintained over the whole lifetime of PMD 7.
This release of PMD brings support for Java 22. There are the following new standard language features, that are supported now:
PMD also supports the following preview language features:
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 22-preview
:
export PMD_JAVA_OPTS=--enable-preview
pmd check --use-version java-22-preview ...
Note: Support for Java 20 preview language features have been removed. The version “20-preview” is no longer available.
CPD-ON
/CPD-OFF
comment pairs.This PMD release ships a new version of the pmd-designer. The designer artifact has been renamed from “pmd-ui” to “pmd-designer”. While the designer still works with Java 8, the recommended Java Runtime is Java 11 (or later) with OpenJFX 17 (or later).
For the detailed changes, see PMD Designer Changelog (7.0.0).
When PMD added Apex support with version 5.5.0, it utilized the Apex Jorje library to parse Apex source and generate an AST. This library is however a binary-blob provided as part of the Salesforce Extensions for VS Code, and it is closed-source.
This causes problems, if binary blobs are not allowed by e.g. a company-wide policy. In that case, the Jorje library prevented that PMD Apex could be used at all.
Also having access to the source code, enhancements and modifications are easier to do.
Under the hood, we use two open source libraries instead:
Although the parser is completely switched, there are only little known changes to the AST. These are documented in the Migration Guide for PMD 7: Apex AST.
With the new Apex parser, the new language constructs like
User Mode Database Operations
and the new Null Coalescing Operator ??
can be parsed now. PMD should be able to parse Apex code up to version 60.0 (Spring ‘24).
See #3766 for details.
Contributors: Aaron Hurst (@aaronhurst-google), Edward Klimoshenko (@eklimo)
There was an inconsistency between the naming of the maven module and the language id. The language id used the abbreviation “vf”, while the maven module used the longer name “visualforce”. This has been solved by renaming the language module to its full name “visualforce”. The java packages have been renamed as well.
If you import rules, you also need to adjust the paths, e.g.
category/vf/security.xml
➡️ category/visualforce/security.xml
Support for HTML was introduced in PMD 6.55.0 as an experimental feature. With PMD 7.0.0 this is now considered stable.
Support for Kotlin was introduced with PMD 7.0.0-rc1 as an experimental feature. With PMD 7.0.0 this is now considered stable.
The module was named just “vm” which was not a good name. Its module name, language id and package names have been renamed to “velocity”.
If you import rules, you also need to adjust the paths, e.g.
category/vm/...
➡️ category/velocity/...
New Rules
OperationWithHighCostInLoop
finds Schema class methods called in a loop, which is a
potential performance issue.UseExplicitTypes
reports usages of var
keyword, which was introduced with Java 10.MissingEncoding
finds XML files without explicit encoding.Changed Rules
EmptyControlStatement
: The rule has a new property to allow empty blocks when
they contain a comment (allowCommentedBlocks
).MethodNamingConventions
: The deprecated rule property skipTestMethodUnderscores
has
been removed. It was actually deprecated since PMD 6.15.0, but was not mentioned in the release notes
back then. Use the property testPattern
instead to configure valid names for test methods.CommentRequired
: The deprecated property headerCommentRequirement
has been removed.
Use the property classCommentRequirement
instead.NonSerializableClass
: The deprecated property prefix
has been removed
without replacement. In a serializable class all fields have to be serializable regardless of the name.Renamed Rulesets
category/vf/security.xml
➡️ category/visualforce/security.xml
category/vm/bestpractices.xml
➡️ category/velocity/bestpractices.xml
category/vm/design.xml
➡️ category/velocity/design.xml
category/vm/errorprone.xml
➡️ category/velocity/errorprone.xml
Removed Rules
The following previously deprecated rules have been finally removed:
OperationWithLimitsInLoop
OperationWithLimitsInLoop
OperationWithLimitsInLoop
NcssCount
NcssCount
NonSerializableClass
EmptyControlStatement
EmptyControlStatement
EmptyControlStatement
EmptyControlStatement
UnnecessarySemicolon
EmptyControlStatement
EmptyControlStatement
EmptyControlStatement
EmptyControlStatement
Removed deprecated rulesets
The following previously deprecated rulesets have been removed. These were the left-over rulesets from PMD 5. The rules have been moved into categories with PMD 6.
n.s.pmd.reporting
packagen.s.pmd.lang.rule
packagecolor
and system property pmd.color
in TextColorRenderer
--no-ruleset-compatibility
--ignore-literals
and --ignore-identifiers
workSee Detailed Release Notes for PMD 7.
The new official logo of PMD:
For more information, see the Detailed Release Notes for PMD 7.
For more information, see the Detailed Release Notes for PMD 7.
Contributors: Clément Fournier (@oowekyala), Andreas Dangel (@adangel), Juan Martín Sotuyo Dodero (@jsotuyod)
pmd
(pmd.bat
for Windows) to launch the different utilities:
pmd check
to run PMD rules and analyze a projectpmd cpd
to run CPD (copy paste detector)pmd designer
to run the PMD Rule Designerpmd check
For more information, see the Detailed Release Notes for PMD 7.
Contributors: Juan Martín Sotuyo Dodero (@jsotuyod)
For more information, see the Detailed Release Notes for PMD 7.
Contributors: Lucas Soncini (@lsoncini), Matías Fraga (@matifraga), Tomás De Lucca (@tomidelucca)
This PMD release ships a new version of the pmd-designer. The designer artifact has been renamed from “pmd-ui” to “pmd-designer”. While the designer still works with Java 8, the recommended Java Runtime is Java 11 (or later) with OpenJFX 17 (or later).
For the detailed changes, see
Thanks to @mohan-chinnappan-n a new CPD report format has been added which features a data table. It uses an XSLT stylesheet to convert CPD’s XML format into HTML.
See the example report.
Contributors: Mohan Chinnappan (@mohan-chinnappan-n)
Note that this is just a concise listing of the highlights. For more information on the languages, see the Detailed Release Notes for PMD 7.
PMD supported Apache Velocity for a very long time, but the CPD integration never got finished.
This is now done and CPD supports Apache Velocity Template language for detecting copy and paste.
It is shipped in the module pmd-velocity
.
Thanks to a contribution, CPD now supports Coco, a modern programming language
designed specifically for building event-driven software. It is shipped in the new
module pmd-coco
.
Contributors: Wener (@wener-tiobe)
Thanks to a contribution, CPD now supports the Julia language. It is shipped
in the new module pmd-julia
.
Contributors: Wener (@wener-tiobe)
Thanks to a contribution, CPD now supports the TypeScript language. It is shipped
with the rest of the JavaScript support in the module pmd-javascript
.
Contributors: Paul Guyot (@pguyot)
This release of PMD brings support for Java 21 and 22. There are the following new standard language features, that are supported now:
PMD also supports the following preview language features:
In order to analyze a project with PMD that uses these preview language features,
you’ll need to enable it via the environment variable PMD_JAVA_OPTS
and select the new language
version 22-preview
:
export PMD_JAVA_OPTS=--enable-preview
pmd check --use-version java-22-preview ...
Note: Support for Java 19 and Java 20 preview language features have been removed. The versions “19-preview” and “20-preview” are no longer available.
Contributors: Jeroen Borgers (@jborgers), Peter Paul Bakker (@stokpop)
Contributors: Lucas Soncini (@lsoncini), Matías Fraga (@matifraga), Tomás De Lucca (@tomidelucca)
When PMD added Apex support with version 5.5.0, it utilized the Apex Jorje library to parse Apex source and generate an AST. This library is however a binary-blob provided as part of the Salesforce Extensions for VS Code, and it is closed-source.
This causes problems, if binary blobs are not allowed by e.g. a company-wide policy. In that case, the Jorje library prevented that PMD Apex could be used at all.
Also having access to the source code, enhancements and modifications are easier to do.
Under the hood, we use two open source libraries instead:
Although the parsers is completely switched, there are only little known changes to the AST.
These are documented in the Migration Guide for PMD 7: Apex AST.
With the new Apex parser, the new language constructs like
User Mode Database Operations
and the new Null Coalescing Operator ??
can be parsed now. PMD should be able to parse Apex code up to version 60.0 (Spring ‘24).
See #3766 for details.
Contributors: Aaron Hurst (@aaronhurst-google), Edward Klimoshenko (@eklimo)
--ignore-sequences
.--ignore-literal-sequences
, only
literals were ignored. The new option additionally ignores identifiers as well in sequences.Contributors: Wener (@wener-tiobe)
CPD-ON
/CPD-OFF
comment pairs.Contributors: Juan Martín Sotuyo Dodero (@jsotuyod)
Support for HTML was introduced in PMD 6.55.0 as an experimental feature. With PMD 7.0.0 this is now considered stable.
minimumLanguageVersion
and
maximumLanguageVersion
attributes.IntProperty
and StringProperty
have been removed. Please use
PropertyFactory
to create properties.,
) as a delimiter. The previous default was a
pipe character (|
). The delimiter is not configurable anymore. If needed, the comma can be escaped
with a backslash.min
and max
attributes in property definitions in the XML are now optional and can appear separately
or be omitted.The module was named just “vm” which was not a good name. Its module name, language id and package names have been renamed to “velocity”.
If you import rules, you also need to adjust the paths, e.g.
category/vm/...
➡️ category/velocity/...
There was an inconsistency between the naming of the maven module and the language id. The language id used the abbreviation “vf”, while the maven module used the longer name “visualforce”. This has been solved by renaming the language module to its full name “visualforce”. The java packages have been renamed as well.
If you import rules, you also need to adjust the paths, e.g.
category/vf/security.xml
➡️ category/visualforce/security.xml
Apex
OperationWithHighCostInLoop
finds Schema class methods called in a loop, which is a
potential performance issue.UnusedMethod
finds unused methods in your code.Java
UnnecessaryBoxing
reports boxing and unboxing conversions that may be made implicit.UseExplicitTypes
reports usages of var
keyword, which was introduced with Java 10.Kotlin
FunctionNameTooShort
finds functions with a too short name.OverrideBothEqualsAndHashcode
finds classes with only
either equals
or hashCode
overridden, but not both. This leads to unexpected behavior once instances
of such classes are used in collections (Lists, HashMaps, …).Swift
ForceCast
flags all force casts, making sure you are
defensively considering all types. Having the application crash shouldn’t be an option.ForceTry
flags all force tries, making sure you are
defensively handling exceptions. Having the application crash shouldn’t be an option.ProhibitedInterfaceBuilder
flags any usage of interface
builder. Interface builder files are prone to merge conflicts, and are impossible to code review, so larger
teams usually try to avoid it or reduce its usage.UnavailableFunction
flags any function throwing
a fatalError
not marked as @available(*, unavailable)
to ensure no calls are actually performed in
the codebase.XML
MissingEncoding
finds XML files without explicit encoding.The information about changed rules, removed rules and rulesets can be found in the Detailed Release Notes for PMD 7.
The API of PMD has been growing over the years and needed some cleanup. The goal is, to have a clear separation between a well-defined API and the implementation, which is internal. This should help us in future development.
Also, there are some improvement and changes in different areas. For the detailed description of the changes listed here, see Detailed Release Notes for PMD 7.
A detailed documentation of required changes are available in the Migration Guide for PMD 7.
See also Detailed Release Notes for PMD 7.
More than 300 issues have been fixed in PMD 7. See Detailed Release Notes for PMD 7 for the complete list of fixed issues.
Many thanks to the following contributors: @219sansim, @aaronhurst-google, @anastasiia-koba, @AndreyBozhko, @bergander, @ciufudean, @cyw3, @dague1, @Debamoy, @eklimo, @ethauvin, @JerritEic, @joaodinissf, @kenji21, @krdabrowski, @lbovet, @lsoncini, @LynnBroe, @marcindabrowski, @matifraga, @mohan-chinnappan-n, @mohui1999, @nawforce, @nirvikpatel, @nwcm, @oleksandr-shvets, @pguyot, @PimvanderLoos, @rcorfieldffdc, @sfdcsteve, @shai-bennathan, @tomidelucca, @tprouvot, @wener-tiobe.
See Detailed Release Notes for PMD 7 for the full list of PRs.