PMD 7.3.0 released

28 June 2024


28-June-2024 - 7.3.0

The PMD team is pleased to announce PMD 7.3.0.

This is a minor release.

Table Of Contents

🚀 New and noteworthy

✨ New Rules

  • The new Java rule UseEnumCollections reports usages for HashSet and HashMap when the keys are of an enum type. The specialized enum collections are more space- and time-efficient.

💥 pmd-compat6 removed (breaking)

The already deprecated PMD 6 compatibility module (pmd-compat6) has been removed. It was intended to be used with older versions of the maven-pmd-plugin, but since maven-pmd-plugin 3.22.0, PMD 7 is supported directly and this module is not needed anymore.

If you currently use this dependency (net.sourceforge.pmd:pmd-compat6), remove it and upgrade maven-pmd-plugin to the latest version (3.23.0 or newer).

See also Maven PMD Plugin.

🐛 Fixed Issues

  • cli
    • #2827: [cli] Consider processing errors in exit status
  • core
    • #4396: [core] CPD is always case sensitive
    • #4992: [core] CPD: Include processing errors in XML report
    • #5066: [core] CPD throws java.lang.OutOfMemoryError: Java heap space (since 7.1.0)
  • apex
    • #4922: [apex] SOQL syntax error with TYPEOF in sub-query
    • #5053: [apex] CPD fails to parse string literals with escaped characters
    • #5055: [apex] SOSL syntax error with WITH USER_MODE or WITH SYSTEM_MODE
  • apex-bestpractices
    • #5000: [apex] UnusedLocalVariable FP with binds in SOSL / SOQL
  • java
    • #4885: [java] AssertionError: Method should be accessible
    • #5050: [java] Problems with pattern variables in switch branches
  • java-bestpractices
    • #577: [java] New Rule: Check that Map<K,V> is an EnumMap if K is an enum value
    • #5047: [java] UnusedPrivateMethod FP for Generics & Overloads
  • plsql
    • #1934: [plsql] ParseException with MERGE statement in anonymous block
    • #2779: [plsql] Error while parsing statement with (Oracle) DML Error Logging
    • #4270: [plsql] Parsing exception COMPOUND TRIGGER with EXCEPTION handler

🚨 API Changes

CPD Report Format XML

There are some important changes:

  1. The XML format will now use an XSD schema, that is available at https://pmd.github.io/schema/cpd-report_1_0_0.xsd. This schema defines the valid elements and attributes that one can expect from a CPD report.
  2. The root element pmd-cpd contains the new attributes pmdVersion, timestamp and version. The latter is the schema version and is currently “1.0.0”.
  3. The CPD XML report will now also contain recoverable errors as additional <error> elements.

See Report formats for CPD for an example.

The XML format should be compatible as only attributes and elements have been added. However, if you parse the document with a namespace aware parser, you might encounter some issues like no elements being found. In case the new format doesn’t work for you (e.g. namespaces, unexpected error elements), you can go back using the old format with the renderer “xmlold” (XMLOldRenderer). Note, that this old renderer is deprecated and only there for compatibility reasons. Whatever tooling is used to read the XML format should be updated.

CLI

  • New exit code 5 introduced. PMD and CPD will exit now by default with exit code 5, if any recoverable error (e.g. parsing exception, lexing exception or rule exception) occurred. PMD will still create a report with all detected violations or duplications if recoverable errors occurred. Such errors mean, that the report might be incomplete, as either violations or duplications for an entire file or for a specific rule are missing. These cases can be considered as false-negatives.

    In any case, the root cause should be investigated. If it’s a problem in PMD itself, please create a bug report.

  • New CLI parameter --no-fail-on-error to ignore such errors and not exit with code 5. By default, a build with errors will now fail and with that parameter, the previous behavior can be restored. This parameter is available for both PMD and CPD.

  • The CLI parameter --skip-lexical-errors is deprecated. By default, lexical errors are skipped but the build is failed. Use the new parameter --[no-]fail-on-error instead to control whether to fail the build or not.

Ant

  • CPDTask has a new parameter failOnError. It controls, whether to fail the build if any recoverable error occurred. By default, the build will fail. CPD will still create a report with all detected duplications, but the report might be incomplete.
  • The parameter skipLexicalError in CPDTask is deprecated and ignored. Lexical errors are now always skipped. Use the new parameter failOnError instead to control whether to fail the build or not.

Deprecated API

Breaking changes: pmd-compat6 removed

The already deprecated PMD 6 compatibility module (pmd-compat6) has been removed. See above for details.

📈 Stats

  • 88 commits
  • 32 closed tickets & PRs
  • Days since last release: 27