All Versions
12
Latest Version
Avg Release Cycle
36 days
Latest Release
8 days ago

Changelog History
Page 1

  • v6.24.0

    May 24, 2020

    24-May-2020 - 6.24.0

    The PMD team is pleased to announce PMD 6.24.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    πŸ‘ CPD now supports XML as well

    Thanks to Fernando Cosso CPD can now find duplicates in XML files as well.
    This is useful to find duplicated sections in XML files.

    ⚑️ Updated PMD Designer

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

    πŸ†• New Rules

    The new Java Rule LiteralsFirstInComparisons (java-bestpractices)
    find String literals, that are used in comparisons and are not positioned first. Using the String literal
    as the receiver of e.g. equals helps to avoid NullPointerExceptions.

    This rule is replacing the two old rules PositionLiteralsFirstInComparisons
    and PositionLiteralsFirstInCaseInsensitiveComparisons and extends the check
    for the methods compareTo, compareToIgnoreCase and contentEquals in addition to equals and
    equalsIgnoreCase.

    Note: This rule also replaces the two mentioned rules in Java's quickstart ruleset.

    πŸ—„ Deprecated Rules

    πŸ›  Fixed Issues

    • apex-bestpractices
      • #2468: [apex] Unused Local Variable fails on blocks
    • core
      • #2444: [core] Support reproducible builds
      • #2484: [core] Update maven-enforcer-plugin to require Java 118
    • c#
      • #2495: [c#] Support for interpolated verbatim strings
    • java
      • #2472: [java] JavaCharStream throws an Error on invalid escape
    • java-bestpractices
      • #2145: [java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons
      • #2288: [java] JUnitTestsShouldIncludeAssert: Add support for Hamcrest MatcherAssert.assertThat
      • #2437: [java] AvoidPrintStackTrace can't detect the case e.getCause().printStackTrace()
    • πŸ’… java-codestyle
      • #2476: [java] MethodNamingConventions - Add support for JUnit 5 method naming
    • java-errorprone
      • #2477: [java] JUnitSpelling false-positive for JUnit5/4 tests
    • swift
      • #2473: [swift] Swift 5 (up to 5.2) support for CPD

    API Changes

    πŸ—„ Deprecated APIs

    Experimental APIs

    Note: Experimental APIs are identified with the annotation Experimental,
    πŸ‘€ see its javadoc for details

    • πŸ“„ The experimental methods in BaseLanguageModule have been replaced by a
      definitive API.

    External Contributions

    Stats

    • 114 commits
    • 29 closed tickets & PRs
    • πŸš€ Days since last release: 30
  • v6.23.0

    April 24, 2020

    24-April-2020 - 6.23.0

    The PMD team is pleased to announce PMD 6.23.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    PMD adopts Contributor Code of Conduct

    To facilitate healthy and constructive community behavior PMD adopts
    Contributor Convenant as its code of
    conduct.

    πŸš€ Please note that this project is released with a Contributor Code of Conduct.
    By participating in this project you agree to abide by its terms.

    You can find the code of conduct in the file code_of_conduct.md
    in our repository.

    🐎 Performance improvements for XPath 2.0 rules

    πŸ‘ XPath rules written with XPath 2.0 now support conversion to a rulechain rule, which
    πŸ‘Œ improves their performance. The rulechain is a mechanism that allows several rules
    to be executed in a single tree traversal. Conversion to the rulechain is possible if
    your XPath expression looks like //someNode/... | //someOtherNode/... | ..., that
    is, a union of one or more path expressions that start with //. Instead of traversing
    the whole tree once per path expression (and per rule), a single traversal executes all
    rules in your ruleset as needed.

    This conversion is performed automatically and cannot be disabled. The conversion should
    not change the result of your rules
    , if it does, please report a bug at https://github.com/pmd/pmd/issues

    πŸ—„ Note that XPath 1.0 support, the default XPath version, is deprecated since PMD 6.22.0.
    ⬆️ We highly recommend that you upgrade your rules to XPath 2.0. Please refer to the migration guide.

    Javascript improvements for ES6

    πŸ“œ PMD uses the Rhino library to parse Javascript.
    0️⃣ The default version has been set to ES6, so that some ECMAScript 2015 features are
    πŸ‘Œ supported. E.g. let statements and for-of loops are now parsed. However Rhino does
    πŸ‘ not support all features.

    πŸ†• New JSON renderer

    πŸ‘ PMD now supports a JSON renderer (use it with -f json on the CLI).
    πŸ‘‰ See the documentation and example

    πŸ†• New Rules

    The new Apex rule FieldDeclarationsShouldBeAtStart (apex-codestyle)
    helps to ensure that field declarations are always at the beginning of a class.

    The new Apex rule UnusedLocalVariable (apex-bestpractices) detects unused
    local variables.

    πŸ›  Fixed Issues

    • apex-design
      • #2358: [apex] Invalid Apex in Cognitive Complexity tests
    • πŸ”’ apex-security
      • #2210: [apex] ApexCRUDViolation: Support WITH SECURITY_ENFORCED
      • #2399: [apex] ApexCRUDViolation: false positive with security enforced with line break
    • core
      • #1286: [core] Export Supporting JSON Format
      • #2019: [core] Insufficient deprecation warnings for XPath attributes
      • #2357: Add code of conduct: Contributor Covenant
      • #2426: [core] CodeClimate renderer links are dead
      • #2432: [core] Close ZIP data sources even if a runtime exception or error is thrown
    • doc
      • #2355: [doc] Improve documentation about incremental analysis
      • #2356: [doc] Add missing doc about pmd.github.io
      • #2412: [core] HTMLRenderer doesn't render links to source files
      • #2413: [doc] Improve documentation about the available renderers (PMD/CPD)
    • java
      • #2378: [java] AbstractJUnitRule has bad performance on large code bases
    • java-bestpractices
      • #2398: [java] AbstractClassWithoutAbstractMethod false negative with inner abstract classes
    • πŸ’… java-codestyle
      • #1164: [java] ClassNamingConventions suggests to add Util for class containing only static constants
      • #1723: [java] UseDiamondOperator false-positive inside lambda
    • java-design
      • #2390: [java] AbstractClassWithoutAnyMethod: missing violation for nested classes
    • java-errorprone
      • #2402: [java] CloseResource possible false positive with Primitive Streams
    • java-multithreading
      • #2313: [java] Documenation for DoNotUseThreads is outdated
    • javascript
      • #1235: [javascript] Use of let results in an Empty Statement in the AST
      • #2379: [javascript] Support for-of loop
    • javascript-errorprone
      • #384: [javascript] Trailing commas not detected on French default locale

    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.

    In ASTs

    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 Apex , Javascript , PL/SQL , Scala and Visualforce ASTs:

    • πŸ—„ 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 VfNode 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 implementation classes of Parser (eg VfParser) are deprecated and should not be used directly.
      πŸ“œ Use LanguageVersionHandler#getParser instead.
    • πŸ—„ The implementation classes of TokenManager (eg VfTokenManager) are deprecated and should not be used outside of our implementation.
      This also affects CPD-only modules.

    πŸš€ These deprecations are added to the following language modules in this release.
    πŸ“š Please look at the package documentation to find out the full list of deprecations.

    πŸ—„ These deprecations have already been rolled out in a previous version for the
    following languages:

    πŸ“¦ Outside of these packages, these changes also concern the following TokenManager
    πŸ“¦ implementations, and their corresponding Parser if it exists (in the same package):

    In the Java AST the following attributes are deprecated and will issue a warning when used in XPath rules:

    For removal

    External Contributions

    Stats

    • 237 commits
    • 64 closed tickets & PRs
    • πŸš€ Days since last release: 42
  • v6.22.0

    March 12, 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
    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

  • v6.21.0

    January 24, 2020

    24-January-2020 - 6.21.0

    The PMD team is pleased to announce PMD 6.21.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    πŸ‘ Modelica support

    πŸ‘ Thanks to Anatoly Trosinenko PMD supports now a new language:
    Modelica is a language to model complex physical systems.
    πŸš€ Both PMD and CPD are supported and there are already 3 rules available.
    πŸ‘ The PMD Designer supports syntax highlighting for Modelica.

    πŸ‘ While the language implementation is quite complete, Modelica support is considered experimental
    for now. This is to allow us to change the rule API (e.g. the AST classes) slightly and improve
    the implementation based on your feedback.

    Simple XML dump of AST

    We added a experimental feature to dump the AST of a source file into XML. The XML format
    is of course PMD specific and language dependent. That XML file can be used to execute
    (XPath) queries against without PMD. It can also be used as a textual visualization of the AST
    if you don't want to use the Designer.

    🚚 This feature is experimental and might change or even be removed in the future, if it is not
    πŸš€ useful. A short description how to use it is available under Creating XML dump of the AST.

    Any feedback about it, especially about your use cases, is highly appreciated.

    ⚑️ Updated Apex Support

    • πŸ‘ The Apex language support has been bumped to version 48 (Spring '20). All new language features are now properly
      πŸ“œ parsed and processed.

    CPD XML format

    The CPD XML output format has been enhanced to also report column information for found duplications
    in addition to the line information. This allows to display the exact tokens, that are considered
    duplicate.

    If a CPD language doesn't provide these exact information, then these additional attributes are omitted.

    Each <file> element in the XML format now has 3 new attributes:

    • attribute endline
    • attribute column (if there is column information available)
    • attribute endcolumn (if there is column information available)

    Modified Rules

    The Java rule AvoidLiteralsInIfCondition (java-errorprone) has a new property
    0️⃣ ignoreExpressions. This property is set by default to true in order to maintain compatibility. If this
    property is set to false, then literals in more complex expressions are considered as well.

    The Apex rule ApexCSRF (apex-errorprone) has been moved from category
    πŸ”’ "Security" to "Error Prone". The Apex runtime already prevents DML statements from being executed, but only
    πŸ‘€ at runtime. So, if you try to do this, you'll get an error at runtime, hence this is error prone. See also
    the discussion on #2064.

    The Java rule CommentRequired (java-documentation) has a new property
    πŸ—„ classCommentRequirement. This replaces the now deprecated property headerCommentRequirement, since
    the name was misleading. (File) header comments are not checked, but class comments are.

    πŸ›  Fixed Issues

    • apex
      • #2208: [apex] ASTFormalComment should implement ApexNode<T>
    • core
      • #1984: [java] Cyclomatic complexity is misreported (lack of clearing metrics cache)
      • #2006: [core] PMD should warn about multiple instances of the same rule in a ruleset
      • #2161: [core] ResourceLoader is deprecated and marked as internal but is exposed
      • #2170: [core] DocumentFile doesn't preserve newlines
    • doc
      • #2214: [doc] Link broken in pmd documentation for writing Xpath rules
    • java
      • #2212: [java] JavaRuleViolation reports wrong class name
    • java-bestpractices
      • #2149: [java] JUnitAssertionsShouldIncludeMessage - False positive with assertEquals and JUnit5
    • πŸ’… java-codestyle
      • #2167: [java] UnnecessaryLocalBeforeReturn false positive with variable captured by method reference
    • πŸ“š java-documentation
      • #1683: [java] CommentRequired property names are inconsistent
    • java-errorprone
      • #2140: [java] AvoidLiteralsInIfCondition: false negative for expressions
      • #2196: [java] InvalidLogMessageFormat does not detect extra parameters when no placeholders
    • 🐎 java-performance
      • #2141: [java] StringInstatiation: False negative with String-array access
    • plsql
      • #2008: [plsql] In StringLiteral using alternative quoting mechanism single quotes cause parsing errors
      • #2009: [plsql] Multiple DDL commands are skipped during parsing

    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.

    CharStream, JavaCharStream,
    SimpleCharStream: these are APIs used by our JavaCC
    ♻️ implementations and that will be moved/refactored for PMD 7.0.0. They should not
    be used, extended or implemented directly.

    πŸ“œ All classes generated by JavaCC, eg JJTJavaParserState.
    This includes token classes, which will be replaced with a single implementation, and
    πŸ‘€ subclasses of ParseException, whose usages will be replaced
    by just that superclass.

    For removal

    External Contributions

  • v6.21.0-with

    January 24, 2020

    πŸš€ This release is identical to the 6.21.0 release, but it includes the newest version of the rule designer. Technically it's a prerelease of 6.22.0 (you'll find that the jar versions reflect this).

    πŸš€ PMD release notes

    πŸš€ Please refer to the 6.21.0 PMD release

    πŸš€ Designer release notes

    πŸš€ Please refer to the 6.21.0 designer release

  • v6.20.0

    November 29, 2019

    29-November-2019 - 6.20.0

    The PMD team is pleased to announce PMD 6.20.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ›  Fixed Issues

    • apex
      • #2092: [apex] ApexLexer logs visible when Apex is the selected language upon starting the designer
      • #2136: [apex] Provide access to underlying query of SoqlExpression
    • core
      • #2002: [doc] Issue with http://pmdapplied.com/ linking to a gambling Web site
      • #2062: [core] Shortnames parameter does not work with Ant
      • #2090: [ci] Release notes and draft releases
      • #2096: [core] Referencing category errorprone.xml produces deprecation warnings for InvalidSlf4jMessageFormat
    • java
      • #1861: [java] Be more lenient with version numbers
      • #2105: [java] Wrong name for inner classes in violations
    • java-bestpractices
      • #2016: [java] UnusedImports: False positive if wildcard is used and only static methods
    • πŸ’… java-codestyle
      • #1362: [java] LinguisticNaming flags Predicates with boolean-style names
      • #2029: [java] UnnecessaryFullyQualifiedName false-positive for non-static nested classes
      • #2098: [java] UnnecessaryFullyQualifiedName: regression / false positive
    • java-design
      • #2075: [java] ImmutableField false positive with inner class
      • #2125: [java] ImmutableField: False positive when variable is updated in conditional loop
    • java-errorprone
      • #2102: [java] False positive MissingStaticMethodInNonInstantiatableClass when inheritors are instantiable

    External Contributions

  • v6.19.0

    October 31, 2019

    31-October-2019 - 6.19.0

    The PMD team is pleased to announce PMD 6.19.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    ⚑️ Updated PMD Designer

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

    Java Metrics

    Modified Rules

    The Java rules InvalidLogMessageFormat and MoreThanOneLogger
    🌲 (java-errorprone) now both support Log4j2. Note that the
    rule "InvalidSlf4jMessageFormat" has been renamed to "InvalidLogMessageFormat" to reflect the fact, that it now
    πŸ‘Œ supports more than slf4j.

    The Java rule LawOfDemeter (java-design) ignores now also Builders, that are
    not assigned to a local variable, but just directly used within a method call chain. The method, that creates
    πŸ— the builder needs to end with "Builder", e.g. newBuilder() or initBuilder() works. This change
    πŸ›  fixes a couple of false positives.

    The Java rule DataflowAnomalyAnalysis (java-errorprone) doesn't check for
    UR anomalies (undefined and then referenced) anymore. These checks were all false-positives, since actual
    UR occurrences would lead to compile errors.

    The java rule DoNotUseThreads (java-multithreading) has been changed
    to not report usages of java.lang.Runnable anymore. Just using Runnable does not automatically create
    🚚 a new thread. While the check for Runnable has been removed, the rule now additionally checks for
    usages of Executors and ExecutorService. Both create new threads, which are not managed by a J2EE
    server.

    πŸ“‡ Renamed Rules

    πŸ›  Fixed Issues

    • core
      • #1978: [core] PMD fails on excluding unknown rules
      • #2014: [core] Making add(SourceCode sourceCode) public for alternative file systems
      • #2020: [core] Wrong deprecation warnings for unused XPath attributes
      • #2036: [core] Wrong include/exclude patterns are silently ignored
      • #2048: [core] Enable type resolution by default for XPath rules
      • #2067: [core] Build issue on Windows
      • #2068: [core] Rule loader should use the same resources loader for the ruleset
      • #2071: [ci] Add travis build on windows
      • #2072: [test][core] Not enough info in "test setup error" when numbers of lines do not match
      • #2082: [core] Incorrect logging of deprecated/renamed rules
    • java
      • #2042: [java] PMD crashes with ClassFormatError: Absent Code attribute...
    • java-bestpractices
      • #1531: [java] UnusedPrivateMethod false-positive with method result
      • #2025: [java] UnusedImports when @see / @link pattern includes a FQCN
    • πŸ’… java-codestyle
      • #2017: [java] UnnecessaryFullyQualifiedName triggered for inner class
    • java-design
      • #1912: [java] Metrics not computed correctly with annotations
    • java-errorprone
      • #336: [java] InvalidSlf4jMessageFormat applies to log4j2
      • #1636: [java] Stop checking UR anomalies for DataflowAnomalyAnalysis
    • java-multithreading
      • #1627: [java] DoNotUseThreads should not warn on Runnable
    • doc
      • #2058: [doc] CLI reference for -norulesetcompatibility shows a boolean default value

    API Changes

    πŸ—„ Deprecated APIs

    For removal
    Internal APIs

    External Contributions

  • v6.18.0

    September 15, 2019

    15-September-2019 - 6.18.0

    The PMD team is pleased to announce PMD 6.18.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    πŸ‘ Java 13 Support

    πŸš€ 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
    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 13-preview:

    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.

    πŸ‘ Full support for Scala

    πŸ‘ 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.

    πŸ†• New rule designer documentation

    πŸ“š 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.

    πŸ†• New rules

    The Java rule AvoidMessageDigestField (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 DebugsShouldUseLoggingLevel (apex-bestpractices) detects
    🌲 usages of 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.

    Modified Rules

    • The Java rule CloseResource (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
      0️⃣ won't be found by default by the rule anymore.

    πŸ›  Fixed Issues

    • all
      • #1465: [core] Stylesheet pmd-report.xslt fails to display filepath if 'java' in path
      • #1923: [core] Incremental analysis does not work with shortnames
      • #1983: [core] Avoid crashes with analysis cache when classpath references non-existing directories
      • #1990: [core] Incremental analysis mixes XPath rule violations
    • apex
      • #1901: [apex] Expose super type name of UserClass
      • #1942: [apex] Add best practice rule for debug statements in Apex
    • java
      • #1930: [java] Add Java 13 support
    • java-bestpractices
      • #1227: [java] UnusedFormalParameter should explain checkAll better
      • #1862: [java] New rule for MessageDigest.getInstance
      • #1952: [java] UnusedPrivateField not triggering if @value annotation present
    • πŸ’… java-codestyle
      • #1951: [java] UnnecessaryFullyQualifiedName rule triggered when variable name clashes with package name
    • java-errorprone
      • #1922: [java] CloseResource possible false positive with Streams
      • #1966: [java] CloseResource false positive if Stream is passed as method parameter
      • #1967: [java] CloseResource false positive with late assignment of variable
    • plsql
      • #1933: [plsql] ParseException with cursor declared in anonymous block
      • #1935: [plsql] ParseException with SELECT INTO record defined as global variable
      • #1936: [plslq] ParseException with cursor inside procedure declaration
      • #1946: [plsql] ParseException with using TRIM inside IF statements condition
      • #1947: [plsql] ParseError - SELECT with FOR UPDATE OF
      • #1948: [plsql] ParseException with INSERT INTO using package global variables
      • #1950: [plsql] ParseException with UPDATE and package record variable
      • #1953: [plsql] ParseException with WITH in CURSOR

    API Changes

    πŸ”„ Changes to Renderer

    Each renderer has now a new method Renderer#setUseShortNames which
    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".

    πŸ—„ Deprecated APIs

    For removal
    Internal APIs

    🚚 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.

    External Contributions

  • v6.17.0

    July 28, 2019

    28-July-2019 - 6.17.0

    The PMD team is pleased to announce PMD 6.17.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    ⚑️ Updated PMD Designer

    πŸš€ This PMD release ships a new version of the pmd-designer.
    πŸš€ For the changes, see PMD Designer Changelog.
    βœ… It contains a new feature to edit test cases directly within the designer. Any feedback is highly appreciated.

    πŸ‘ Lua support

    πŸ‘ Thanks to the contribution from Maikel Steneker, and built on top of the ongoing efforts to fully support Antlr-based languages,
    πŸ‘ PMD now has CPD support for Lua.

    Being based on a proper Antlr grammar, CPD can:

    Modified Rules

    The Java rule CloseResource (java-errorprone) ignores now by default
    java.io.ByteArrayInputStream and java.io.CharArrayWriter. Such streams/writers do not need to be closed.

    The Java rule MissingStaticMethodInNonInstantiatableClass (java-errorprone) has now
    the new property annotations.
    When one of the private constructors is annotated with one of the annotations, then the class is not considered
    0️⃣ non-instantiatable anymore and no violation will be reported. By default, Spring's @Autowired and
    Java EE's @Inject annotations are recognized.

    πŸ›  Fixed Issues

    • core
      • #1913: [core] "-help" CLI option ends with status code != 0
    • doc
      • #1896: [doc] Error in changelog 6.16.0 due to not properly closed rule tag
      • #1898: [doc] Incorrect code example for DoubleBraceInitialization in documentation on website
      • #1906: [doc] Broken link for adding own CPD languages
      • #1909: [doc] Sample usage example refers to deprecated ruleset "basic.xml" instead of "quickstart.xml"
    • java
      • #1910: [java] ATFD calculation problem
    • java-errorprone
      • #1749: [java] DD False Positive in DataflowAnomalyAnalysis
      • #1832: [java] False positives for MissingStaticMethodInNonInstantiatableClass when DI is used
      • #1921: [java] CloseResource false positive with ByteArrayInputStream
    • java-multithreading
      • #1903: [java] UnsynchronizedStaticFormatter doesn't allow block-level synchronization when using allowMethodLevelSynchronization=true
    • plsql
      • #1902: [pslql] ParseException when parsing (+)
    • xml
      • #1666: [xml] wrong cdata rule description and examples

    External Contributions

    • #1869: [xml] fix #1666 wrong cdata rule description and examples - Artem
    • πŸ‘ #1892: [lua] [cpd] Added CPD support for Lua - Maikel Steneker
    • #1905: [java] DataflowAnomalyAnalysis Rule in right order - YoonhoChoi96
    • ⚑️ #1908: [doc] Update ruleset filename from deprecated basic.xml to quickstart.xml - crunsk
    • #1916: [java] Exclude Autowired and Inject for MissingStaticMethodInNonInstantiatableClass - AnthonyKot
    • #1917: [core] Add 'no error' return option, and assign it to the cli when the help command is invoked - Renato Oliveira
  • v6.16.0

    June 30, 2019

    30-June-2019 - 6.16.0

    The PMD team is pleased to announce PMD 6.16.0.

    πŸš€ This is a minor release.

    Table Of Contents

    πŸ†• New and noteworthy

    ⚑️ Updated PMD Designer

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

    ⚑️ PLSQL Grammar Updates

    ⚑️ The grammar has been updated to support inline constraints in CREATE TABLE statements. Additionally, the
    CREATE TABLE statement may now be followed by physical properties and table properties. However, these
    πŸ“œ properties are skipped over during parsing.

    πŸ‘ The CREATE VIEW statement now supports subquery views.

    πŸ“œ The EXTRACT function can now be parsed correctly. It is used to extract values from a specified
    πŸ“œ datetime field. Also date time literals are parsed now correctly.

    The CASE expression can now be properly used within SELECT statements.

    πŸ‘ Table aliases are now supported when specifying columns in INSERT INTO clauses.

    πŸ†• New Rules

    The Java rule DoubleBraceInitialization (java-bestpractices)
    detects non static initializers in anonymous classes also known as "double brace initialization".
    This can be problematic, since a new class file is generated and object holds a strong reference
    to the surrounding class.

    Note: This rule is also part of the Java quickstart ruleset (rulesets/java/quickstart.xml).

    Modified Rules

    The Java rule UnusedPrivateField (java-bestpractices) now ignores by
    0️⃣ default fields, that are annotated with the Lombok experimental annotation @Delegate. This can be
    customized with the property ignoredAnnotations.

    The Java rule SingularField (java-design) now ignores by
    0️⃣ default fields, that are annotated with the Lombok experimental annotation @Delegate. This can be
    customized with the property ignoredAnnotations.

    The Java rules UnsynchronizedStaticFormatter and
    UnsynchronizedStaticDateFormatter (java-multithreading)
    πŸ”€ now prefer synchronized blocks by default. They will raise a violation, if the synchronization is implemented
    on the method level. To allow the old behavior, the new property allowMethodLevelSynchronization can
    be enabled.

    The Java rule UseUtilityClass (java-design) has a new property ignoredAnnotations.
    0️⃣ By default, classes that are annotated with Lombok's @UtilityClass are ignored now.

    The Java rule NonStaticInitializer (java-errorprone) does not report
    non static initializers in anonymous classes anymore. For this use case, there is a new rule now:
    DoubleBraceInitialization (java-bestpractices).

    The Java rule CommentDefaultAccessModifier (java-codestyle) was enhanced
    0️⃣ in the last version 6.15.0 to check also top-level types by default. This created many new violations.
    πŸš‘ Missing the access modifier for top-level types is not so critical, since it only decreases the visibility
    of the type.

    βͺ The default behaviour has been restored. If you want to enable the check for top-level types, you can
    πŸ‘‰ use the new property checkTopLevelTypes.

    The Java rule CloseResource (java-errorprone) now by default searches
    for any unclosed java.lang.AutoCloseable resource. This includes now the standard java.io.*Stream classes.
    πŸ”§ Previously only SQL-related resources were considered by this rule. The types can still be configured
    via the types property. Some resources do not need to be closed (e.g. ByteArrayOutputStream). These
    πŸ”§ exceptions can be configured via the new property allowedResourceTypes.
    βͺ In order to restore the old behaviour, just remove the type java.lang.AutoCloseable from the types
    property and keep the remaining SQL-related classes.

    πŸ—„ Deprecated Rules

    • The Java rule AvoidFinalLocalVariable (java-codestyle) has been deprecated
      🚚 and will be removed with PMD 7.0.0. The rule is controversial and also contradicts other existing
      rules such as LocalVariableCouldBeFinal. If the goal is to avoid defining
      constants in a scope smaller than the class, then the rule AvoidDuplicateLiterals
      should be used instead.

    πŸ›  Fixed Issues

    • apex
      • #1664: [apex] False positive ApexSharingViolationsRule, unsupported Apex feature
    • java
      • #1848: [java] Local classes should preserve their modifiers
    • java-bestpractices
      • #1703: [java] UnusedPrivateField on member annotated with lombok @DeleGate
      • #1845: [java] Regression in MethodReturnsInternalArray not handling enums
      • #1854: [java] Rule to check for double brace initialisation
    • πŸ’… java-codestyle
      • #1612: [java] Deprecate AvoidFinalLocalVariable
      • #1880: [java] CommentDefaultAccessModifier should be configurable for top-level classes
    • java-design
      • #1094: [java] UseUtilityClass should be LombokAware
    • java-errorprone
      • #1000: [java] The rule CloseResource should deal with IO stream as default
      • #1853: [java] False positive for NonStaticInitializer in anonymous class
    • java-multithreading
      • #1814: [java] UnsynchronizedStaticFormatter documentation and implementation wrong
      • #1815: [java] False negative in UnsynchronizedStaticFormatter
    • plsql
      • #1828: [plsql] Parentheses stopped working
      • #1850: [plsql] Parsing errors with INSERT using returning or records and TRIM expression
      • #1873: [plsql] Expression list not working
      • #1878: [pslql] ParseException when parsing USING
      • #1879: [pslql] ParseException when parsing LEFT JOIN

    API Changes

    πŸ—„ Deprecated APIs

    🚚 > Reminder: Please don't use members marked with the annotation InternalApi, as they will likely be removed, hidden, or otherwise intentionally broken with 7.0.0.

    In ASTs

    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 Java 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 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. Version 7.0.0 will bring a new set of abstractions that will be public API, but the base classes are and will stay internal. You should not couple your code to them.
      • In the meantime you should use interfaces like JavaNode 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.

    πŸ“¦ Please look at net.sourceforge.pmd.lang.java.ast to find out the full list
    πŸ—„ of deprecations.

    External Contributions