??-????-2020 - 6.22.0
The PMD team is pleased to announce PMD 6.22.0.
This is a minor release.
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
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).
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
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, egJavaRuleViolationFactory
. See javadoc ofRuleViolationFactory
. -
Implementations of
RuleViolation
in each language module, egJavaRuleViolation
. See javadoc ofRuleViolation
. RuleFactory
RuleBuilder
- Constructors of
RuleSetFactory
, use factory methods fromRulesetsFactoryUtils
instead AbstractApexNode
AbstractApexNodeBase
, 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
net.sourceforge.pmd.lang.java.qname
and its contentsMethodLikeNode
- Its methods will also be removed from its implementations,
ASTMethodOrConstructorDeclaration
,ASTLambdaExpression
.
- Its methods will also be removed from its implementations,
ASTAnyTypeDeclaration#getImage
will be removed. Please usegetSimpleName()
instead. This affectsASTAnnotationTypeDeclaration#getImage
,ASTClassOrInterfaceDeclaration#getImage
, andASTEnumDeclaration#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
PLSQL AST
The production and node ASTCursorBody
was unnecessary, not used and has been removed. Cursors have been already
parsed as ASTCursorSpecification
.
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