PMD 5.8.0 released

24 June 2017

24-June-2017 - 5.8.0

The PMD team is pleased to announce PMD 5.8.0.

This is a minor release.

Table Of Contents

New and noteworthy

#### Java Type Resolution

As part of Google Summer of Code 2017, Bendegúz Nagy has been working on completing type resolution for Java. His progress so far has allowed to properly resolve, in addition to previously supported statements:

  • References to this and super, even when qualified
  • References to fields, even when chained (ie: this.myObject.aField), and properly handling inheritance / shadowing

Lambda parameter types where these are infered rather than explicit are still not supported. Expect future releases to do so.

Metrics Framework

As part of Google Summer of Code 2017, Clément Fournier has been working on a new metrics framework for object-oriented metrics.

The basic groundwork has been done already and with this release, including a first rule based on the metrics framework as a proof-of-concept: The rule CyclomaticComplexity, currently in the temporary ruleset java-metrics, uses the Cyclomatic Complexity metric to find overly complex code. This rule will eventually replace the existing three CyclomaticComplexity rules that are currently defined in the java-codesize ruleset (see also issue #445).

Since this work is still in progress, the metrics API (package is not finalized yet and is expected to change.

Modified Rules

  • The Java rule UnnecessaryFinalModifier (ruleset java-unnecessary) now also reports on private methods marked as final. Being private, such methods can’t be overriden, and therefore, the final keyword is redundant.

  • The Java rule PreserveStackTrace (ruleset java-design) has been relaxed to support the builder pattern on thrown exception. This change may introduce some false positives if using the exception in non-orthodox ways for things other than setting the root cause of the exception. Contact us if you find any such scenarios.

  • The ruleset java-junit now properly detects JUnit5, and rules are being adapted to the changes on it’s API. This support is, however, still incomplete. Let us know of any uses we are still missing on the issue tracker

  • The Java rule EmptyTryBlock (ruleset java-empty) now allows empty blocks when using try-with-resources.

  • The Java rule EmptyCatchBlock (ruleset java-empty) now exposes a new property called allowExceptionNameRegex. This allow to setup a regular expression for names of exceptions you wish to ignore for this rule. For instance, setting it to ^(ignored|expected)$ would ignore all empty catch blocks where the catched exception is named either ignored or expected. The default ignores no exceptions, being backwards compatible.

Deprecated Rules

  • The three complexity rules CyclomaticComplexity, StdCyclomaticComplexity, ModifiedCyclomaticComplexity (ruleset java-codesize) have been deprecated. They will be eventually replaced by a new CyclomaticComplexity rule based on the metrics framework. See also issue #445.

Fixed Issues

  • General
    • #380: [core] NPE in RuleSet.hashCode
    • #407: [web] Release date is not properly formatted
    • #429: [core] Error when running PMD from folder with space
  • apex
    • #427: [apex] CPD error when parsing apex code from release 5.5.3
  • cpp
    • #431: [cpp] CPD gives wrong duplication blocks for CPP code
  • java
    • #414: [java] Java 8 parsing problem with annotations for wildcards
    • #415: [java] Parsing Error when having an Annotated Inner class
    • #417: [java] Parsing Problem with Annotation for Array Member Types
  • java-design
    • #397: [java] ConstructorCallsOverridableMethodRule: false positive for method called from lambda expression
    • #410: [java] ImmutableField: False positive with lombok
    • #422: [java] PreserveStackTraceRule: false positive when using builder pattern
  • java-empty
    • #413: [java] EmptyCatchBlock don’t fail when exception is named ignore / expected
    • #432: [java] EmptyTryBlock: false positive for empty try-with-resource
  • java-imports:
    • #348: [java] imports/UnusedImport rule not considering static inner classes of imports
  • java-junit
    • #428: [java] PMD requires public modifier on JUnit 5 test
    • #465: [java] NullPointerException in JUnitTestsShouldIncludeAssertRule
  • java-logging:
    • #365: [java] InvalidSlf4jMessageFormat does not handle inline incrementation of arguments
  • java-strictexceptions
    • #350: [java] Throwing Exception in method signature is fine if the method is overriding or implementing something
  • java-typeresolution
    • #350: [java] Throwing Exception in method signature is fine if the method is overriding or implementing something
  • java-unnecessary
    • #421: [java] UnnecessaryFinalModifier final in private method
  • jsp
    • #311: [jsp] Parse error on HTML boolean attribute

External Contributions

  • #406: [java] False positive with lambda in java-design/ConstructorCallsOverridableMethod
  • #409: [java] Groundwork for the upcoming metrics framework
  • #416: [java] FIXED: Java 8 parsing problem with annotations for wildcards
  • #418: [java] Type resolution: super and this keywords
  • #423: [java] Add field access type resolution in non-generic cases
  • #425: [java] False positive with builder pattern in java-design/PreserveStackTrace
  • #426: [java] UnnecessaryFinalModifier final in private method
  • #436: [java] Metrics framework tests and various improvements
  • #440: [core] Created ruleset schema 3.0.0 (to use metrics)
  • #443: [java] Optimize typeresolution, by skipping package and import declarations in visit(ASTName)
  • #444: [java] [typeresolution]: add support for generic fields
  • #451: [java] Metrics framework: first metrics + first rule