PMD v6.22.0 Release Notes

Release Date: 2020-03-12 // about 4 years ago
  • 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
    0️⃣ 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.

    JavaLanguageHandler

    πŸ“œ JavaLanguageParser

    JavaDataFlowHandler

    Implementations of RuleViolationFactory in each
    language module, eg JavaRuleViolationFactory.
    πŸ‘€ See javadoc of RuleViolationFactory.

    Implementations of RuleViolation in each language module,
    πŸ‘€ eg JavaRuleViolation. See javadoc of
    RuleViolation.

    RuleFactory

    RuleBuilder

    Constructors of RuleSetFactory, use factory methods from RulesetsFactoryUtils instead

    getRulesetFactory

    AbstractApexNode

    AbstractApexNodeBase, and the related visit
    πŸ“œ methods on ApexParserVisitor and its implementations.
    πŸ‘‰ Use ApexNode instead, now considers comments too.

    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