PMD 6.22.0 released

12 March 2020


12-March-2020 - 6.22.0

The PMD team is pleased to announce PMD 6.22.0.

This is a minor release.

Table Of Contents

New and noteworthy

Java 14 Support

This release of PMD brings support for Java 14. PMD can parse Switch Expressions, which have been promoted to be a standard language feature of Java.

PMD also parses Text Blocks as String literals, which is still a preview language feature in Java 14.

The new Pattern Matching for instanceof can be used as well as Records.

Note: The Text Blocks, Pattern Matching for instanceof and Records are all preview language features of OpenJDK 14 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 variable PMD_JAVA_OPTS and select the new language version 14-preview:

export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 14-preview ...

Note: Support for the extended break statement introduced in Java 12 as a preview language feature has been removed from PMD with this version. The version “12-preview” is no longer available.

Updated PMD Designer

This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

Apex Suppressions

In addition to suppressing violation with the @SuppressWarnings annotation, Apex now also supports the suppressions with a NOPMD comment. See Suppressing warnings.

Improved CPD support for C#

The C# tokenizer is now based on an antlr grammar instead of a manual written tokenizer. This should give more accurate results and especially fixes the problems with the using statement syntax (see #2139).

XPath Rules

See the new documentation about Writing XPath Rules.

Note: As of PMD version 6.22.0, XPath versions 1.0 and the 1.0 compatibility mode are deprecated. XPath 2.0 is superior in many ways, for example for its support for type checking, sequence values, or quantified expressions. For a detailed but approachable review of the features of XPath 2.0 and above, see the Saxon documentation.

New Rules

  • The Rule CognitiveComplexity (apex-design) finds methods and classes that are highly complex and therefore difficult to read and more costly to maintain. In contrast to cyclomatic complexity, this rule uses “Cognitive Complexity”, which is a measure of how difficult it is for humans to read and understand a method.

  • The Rule TestMethodsMustBeInTestClasses (apex-errorprone) finds test methods that are not residing in a test class. The test methods should be moved to a proper test class. Support for tests inside functional classes was removed in Spring-13 (API Version 27.0), making classes that violate this rule fail compile-time. This rule is however useful when dealing with legacy code.

Fixed Issues

  • apex
    • #1087: [apex] Support suppression via //NOPMD
    • #2306: [apex] Switch statements are not parsed/supported
  • apex-design
    • #2162: [apex] Cognitive Complexity rule
  • apex-errorprone
    • #639: [apex] Test methods should not be in classes other than test classes
  • cs
    • #2139: [cs] CPD doesn’t understand alternate using statement syntax with C# 8.0
  • doc
    • #2274: [doc] Java API documentation for PMD
  • java
    • #2159: [java] Prepare for JDK 14
    • #2268: [java] Improve TypeHelper resilience
  • java-bestpractices
    • #2277: [java] FP in UnusedImports for ambiguous static on-demand imports
  • java-design
    • #911: [java] UselessOverridingMethod false positive when elevating access modifier
  • java-errorprone
    • #2242: [java] False-positive MisplacedNullCheck reported
    • #2250: [java] InvalidLogMessageFormat flags logging calls using a slf4j-Marker
    • #2255: [java] InvalidLogMessageFormat false-positive for a lambda argument
  • java-performance
    • #2275: [java] AppendCharacterWithChar flags literals in an expression
  • plsql
    • #2325: [plsql] NullPointerException while running parsing test for CREATE TRIGGER
    • #2327: [plsql] Parsing of WHERE CURRENT OF
    • #2328: [plsql] Support XMLROOT
    • #2331: [plsql] Fix in Comment statement
    • #2332: [plsql] Fixed Execute Immediate statement parsing
    • #2340: [plsql] Fixed parsing / as divide or execute

API Changes

Deprecated APIs

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.

For removal
In ASTs (JSP)

As part of the changes we’d like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the JSP AST (with other languages to come):

  • Manual instantiation of nodes. Constructors of node classes are deprecated and marked InternalApi. Nodes should only be obtained from the parser, which for rules, means that they never need to instantiate node themselves. Those constructors will be made package private with 7.0.0.
  • Subclassing of abstract node classes, or usage of their type. The base classes are internal API and will be hidden in version 7.0.0. You should not couple your code to them.
    • In the meantime you should use interfaces like JspNode or Node, or the other published interfaces in this package, to refer to nodes generically.
    • Concrete node classes will be made final with 7.0.0.
  • Setters found in any node class or interface. Rules should consider the AST immutable. We will make those setters package private with 7.0.0.
  • The class JspParser is deprecated and should not be used directly. Use LanguageVersionHandler#getParser instead.

Please look at net.sourceforge.pmd.lang.jsp.ast to find out the full list of deprecations.

In ASTs (Velocity)

As part of the changes we’d like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the VM AST (with other languages to come):

  • Manual instantiation of nodes. Constructors of node classes are deprecated and marked InternalApi. Nodes should only be obtained from the parser, which for rules, means that they never need to instantiate node themselves. Those constructors will be made package private with 7.0.0.
  • Subclassing of abstract node classes, or usage of their type. The base classes are internal API and will be hidden in version 7.0.0. You should not couple your code to them.
    • In the meantime you should use interfaces like VmNode or Node, or the other published interfaces in this package, to refer to nodes generically.
    • Concrete node classes will be made final with 7.0.0.
  • Setters found in any node class or interface. Rules should consider the AST immutable. We will make those setters package private with 7.0.0.
  • The package net.sourceforge.pmd.lang.vm.directive as well as the classes DirectiveMapper and LogUtil are deprecated for removal. They were only used internally during parsing.
  • The class VmParser is deprecated and should not be used directly. Use LanguageVersionHandler#getParser instead.

Please look at net.sourceforge.pmd.lang.vm.ast to find out the full list of deprecations.

PLSQL AST

The production and node ASTCursorBody was unnecessary, not used and has been removed. Cursors have been already parsed as ASTCursorSpecification.

External Contributions