The PMD team is pleased to announce PMD 6.18.0.
This is a minor release.
This release of PMD brings support for Java 13. PMD can parse Switch Expressions
with the new
yield statement and resolve the type of such an expression.
PMD also parses Text Blocks as String literals.
Note: The Switch Expressions and Text Blocks are a preview language feature of OpenJDK 13
and are not enabled by default. In order to
analyze a project with PMD that uses these language features, you’ll need to enable it via the environment
PMD_JAVA_OPTS and select the new language version
export PMD_JAVA_OPTS=--enable-preview ./run.sh pmd -language java -version 13-preview ...
Note: Support for the extended break statement introduced in Java 12 as a preview language feature will be removed with the next PMD version 6.19.0.
Thanks to Chris Smith PMD now fully supports Scala. Now rules for analyzing Scala code can be developed in addition to the Copy-Paste-Detection (CPD) functionality. There are no rules yet, so contributions are welcome.
Additionally Scala support has been upgraded from 2.12.4 to 2.13.
The documentation for the rule designer is now available on the main PMD documentation page: Rule Designer Reference. Check it out to learn about the usage and features of the rule designer.
The Java rule
java-bestpractices) detects fields
of the type
java.security.MessageDigest. Using a message digest instance as a field would need to be
synchronized, as it can easily be used by multiple threads. Without synchronization the calculated hash could
be entirely wrong. Instead of declaring this as a field and synchronize access to use it from multiple threads,
a new instance should be created when needed. This rule is also active when using java’s quickstart ruleset.
The Apex rule
System.debug() method calls that are used without specifying the log level. Having the log
level specified provides a cleaner log, and improves readability of it.
java-errorprone) now ignores by default instances of
java.util.stream.Stream. These streams are
AutoCloseable, but most streams are backed by collections, arrays, or generating functions, which require no special resource management. However, there are some exceptions: The stream returned by
Files::lines(Path)is backed by a actual file and needs to be closed. These instances won’t be found by default by the rule anymore.
Each renderer has now a new method
is used for implementing the “shortnames” CLI option. The method is automatically called by PMD, if this
CLI option is in use. When rendering filenames to the report, the new helper method
AbstractRenderer#determineFileName should be used. This will change
the filename to a short name, if the CLI option “shortnames” is used.
Not adjusting custom renderers will make them render always the full file names and not honoring the CLI option “shortnames”.
getPackagehave been deprecated and will be removed with PMD 7.0.0.
RuleContext#setSourceCodeFilenamehas been deprecated and will be removed. The already existing method
RuleContext#setSourceCodeFileshould be used instead. The method
RuleContext#getSourceCodeFilenamestill exists and returns just the filename without the full path.
AbstractPMDProcessor#filenameFromhas been deprecated. It was used to determine a “short name” of the file being analyzed, so that the report can use short names. However, this logic has been moved to the renderers.
Reporthave been deprecated. They were leftovers from a previous deprecation round targeting
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.