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
variablePMD_JAVA_OPTS
and select the new language version14-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 aNOPMD
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
- 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
- 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
- π 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.π
JavaLanguageParser
Implementations of
RuleViolationFactory
in each
language module, egJavaRuleViolationFactory
.
π See javadoc ofRuleViolationFactory
.Implementations of
RuleViolation
in each language module,
π egJavaRuleViolation
. See javadoc of
RuleViolation
.Constructors of
RuleSetFactory
, use factory methods fromRulesetsFactoryUtils
insteadAbstractApexNodeBase
, and the relatedvisit
π methods onApexParserVisitor
and its implementations.
π UseApexNode
instead, now considers comments too.For removal
- pmd-core
DFAGraphRule
and its implementationsDFAGraphMethod
- Many methods on the
Node
interface
π andAbstractNode
base class. See their javadoc for details. Node#isFindBoundary
is deprecated for XPath queries.- Many APIs of
net.sourceforge.pmd.lang.metrics
, though most of them were internal and
probably not used directly outside of PMD. UseMetricsUtil
as
a replacement for the language-specific façades too. QualifiableNode
,QualifiedName
- pmd-java
AbstractJavaParser
AbstractJavaHandler
ASTAnyTypeDeclaration.TypeKind
ASTAnyTypeDeclaration#getKind
JavaQualifiedName
ASTCatchStatement#getBlock
ASTCompilationUnit#declarationsAreInDefaultPackage
JavaQualifiableNode
ASTAnyTypeDeclaration#getQualifiedName
ASTMethodOrConstructorDeclaration#getQualifiedName
ASTLambdaExpression#getQualifiedName
net.sourceforge.pmd.lang.java.qname
and its contentsMethodLikeNode
- Its methods will also be removed from its implementations,
ASTMethodOrConstructorDeclaration
,
ASTLambdaExpression
. ASTAnyTypeDeclaration#getImage
will be removed. Please usegetSimpleName()
instead. This affectsASTAnnotationTypeDeclaration#getImage
,
ASTClassOrInterfaceDeclaration#getImage
, and
ASTEnumDeclaration#getImage
.- Several methods of
ASTTryStatement
, replacements with other names
β have been added. This includes the XPath attribute@Finally
, replace it with a test forchild::FinallyStatement
. - Several methods named
getGuardExpressionNode
are replaced withgetCondition
. This affects the
following nodes: WhileStatement, DoStatement, ForStatement, IfStatement, AssertStatement, ConditionalExpression. ASTYieldStatement
will not implementTypeNode
β anymore come 7.0.0. Test the type of the expression nested within it.JavaMetrics
,JavaMetricsComputer
ASTArguments#getArgumentCount
.
π Usesize
instead.ASTFormalParameters#getParameterCount
.
π Usesize
instead.
- pmd-apex
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
π markedInternalApi
. 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. - 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.
π UseLanguageVersionHandler#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
π markedInternalApi
. 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. - 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
andLogUtil
are deprecated
π for removal. They were only used internally during parsing. - π The class
VmParser
is deprecated and should not be used directly.
π UseLanguageVersionHandler#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 asASTCursorSpecification
.External Contributions
- #2251: [java] FP for InvalidLogMessageFormat when using slf4j-Markers - Kris Scheibe
- π #2253: [modelica] Remove duplicated dependencies - Piotrek Ε»ygieΕo
- π #2256: [doc] Corrected XML attributes in release notes - Maikel Steneker
- #2276: [java] AppendCharacterWithCharRule ignore literals in expressions - Kris Scheibe
- #2278: [java] fix UnusedImports rule for ambiguous static on-demand imports - Kris Scheibe
- π #2279: [apex] Add support for suppressing violations using the // NOPMD comment - Gwilym Kuiper
- #2280: [cs] CPD: Replace C# tokenizer by an Antlr-based one - Maikel Steneker
- #2297: [apex] Cognitive complexity metrics - Gwilym Kuiper
- β #2317: [apex] New Rule - Test Methods Must Be In Test Classes - Brian NΓΈrremark
- π #2321: [apex] Support switch statements correctly in Cognitive Complexity - Gwilym Kuiper
- π #2326: [plsql] Added XML functions to parser: extract(xml), xml_root and fixed xml_forest - Piotr Szymanski
- π #2327: [plsql] Parsing of WHERE CURRENT OF added - Piotr Szymanski
- #2331: [plsql] Fix in Comment statement - Piotr Szymanski
- π #2332: [plsql] Fixed Execute Immediate statement parsing - Piotr Szymanski
- π #2338: [cs] CPD: fixes in filtering of using directives - Maikel Steneker
- π #2339: [cs] CPD: Fixed CPD --ignore-usings option - Maikel Steneker
- π #2340: [plsql] fix for parsing / as divide or execute - Piotr Szymanski
- β‘οΈ #2342: [xml] Update property used in example - Piotrek Ε»ygieΕo
- β‘οΈ #2344: [doc] Update ruleset examples for ant - Piotrek Ε»ygieΕo
- #2343: [ci] Disable checking for snapshots in jcenter - Piotrek Ε»ygieΕo