🚀 Major Features and Enhancements
New official logo
Many of you probably have already seen the new logo, but now it’s time to actually ship it. The new logo was long ago decided (see #1663).
We decided it’s time to have a modernized logo and get rid of the gun. This allows to include the logo anywhere without offense.
The official logo is also without a tagline (such as “Code Quality Matters!”) as the tagline created some controversies. Without a tagline, we are not limited in the direction of future development of PMD.
The new logo is available from the Logo Project Page.
Revamped Java
The Java grammar has been refactored substantially in order to make it easier to maintain and more correct regarding the Java Language Specification. It supports now also the edge-cases where PMD 6 was failing (e.g. annotations were not supported everywhere). Changing the grammar entails a changed AST and therefore changed rules. The PMD built-in rules have all been upgraded and many bugs have been fixed on the way. Unfortunately, if you are using custom rules, you will most probably need to accommodate these changes yourself.
The type resolution framework has been rewritten from scratch and should now cover the entire Java spec correctly. The same is true for the symbol table. PMD 6 on the other hand has always had problems with advanced type inference, e.g. with lambdas and call chains. Since it was built on the core reflection API, it also was prone to linkage errors and classloader leaks for instance. PMD 7 does not need to load classes, and does not have these problems.
The AST exposes much more semantic information now. For instance, you can jump from a method call to
the declaration of the method being called, or from a field access to the field declaration. These
improvements allow interesting rules to be written that need precise knowledge of the types
in the program, for instance to detect UnnecessaryBoxing
or UseDiamondOperator
.
These are just a small preview of the new rules we will be adding in the PMD 7 release cycle.
Overall, the changes to the parser, AST, type resolution and symbol table code has made PMD for Java significantly faster. On average, we have seen ~2-3X faster analysis, but as usual, this may change depending on your workload, configuration and ruleset.
Contributors: ClĂ©ment Fournier (@oowekyala), Andreas Dangel (@adangel), Juan MartĂn Sotuyo Dodero (@jsotuyod)
Annotations
Annotations are consolidated into a single node. SingleMemberAnnotation
, NormalAnnotation
and MarkerAnnotation
are removed in favour of ASTAnnotation
. The Name node is removed, replaced by a
ASTClassOrInterfaceType
.
Those different node types implement a syntax-only distinction, that only makes semantically equivalent annotations
have different possible representations. For example, @A
and @A()
are semantically equivalent, yet they were
parsed as MarkerAnnotation resp. NormalAnnotation. Similarly, @A("")
and @A(value="")
were parsed as
SingleMemberAnnotation resp. NormalAnnotation. This also makes parsing much simpler. The nested ClassOrInterface
type is used to share the disambiguation logic.
Related issue: [java] Use single node for annotations (#2282)
Annotation AST Examples
Code | Old AST (PMD 6) | New AST (PMD 7) |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Types
-
ASTType
andASTReferenceType
have been turned into interfaces, implemented byASTPrimitiveType
,ASTClassOrInterfaceType
, and the new nodeASTArrayType
. This reduces the depth of the relevant subtrees, and allows to explore them more easily and consistently. -
ASTClassOrInterfaceType
appears to be left recursive now. TODO document that when we’re done discussing the semantic rewrite phase. -
Migrating
- There is currently no way to match abstract types (or interfaces) with XPath, so
Type
andReferenceType
name tests won’t match anything anymore. Type/ReferenceType/ClassOrInterfaceType
->ClassOrInterfaceType
Type/PrimitiveType
->PrimitiveType
.Type/ReferenceType[@ArrayDepth>1]/ClassOrInterfaceType
->ArrayType/ClassOrInterfaceType
.Type/ReferenceType/PrimitiveType
->ArrayType/PrimitiveType
.- Note that in most cases you should check the type of a variable with e.g.
VariableDeclaratorId[pmd-java:typeIs("java.lang.String[]")]
because it considers the additional dimensions on declarations likeString foo[];
. The Java equivalent isTypeHelper.isA(id, String[].class);
- There is currently no way to match abstract types (or interfaces) with XPath, so
Declarations
TODO
Statements
TODO
Expressions
-
ASTExpression
andASTPrimaryExpression
have been turned into interfaces. These added no information to the AST and increased its depth unnecessarily. All expressions implement the first interface. Both of those nodes can no more be found in ASTs. - Migrating:
- Basically,
Expression/X
orExpression/PrimaryExpression/X
, just becomesX
- There is currently no way to match abstract or interface types with XPath, so
Expression
orPrimaryExpression
name tests won’t match anything anymore. However, the axis step *[@Expression=true()] matches any expression.
- Basically,
ASTLiteral
has been turned into an interface. The fact thatASTNullLiteral
andASTBooleanLiteral
were nested within it but other literals types were all directly represented by it was inconsistent, and ultimately that level of nesting was unnecessary.ASTNumericLiteral
,ASTCharLiteral
,ASTStringLiteral
, andASTClassLiteral
are new nodes that implement that interface.- ASTLiteral implements
ASTPrimaryExpression
- Migrating:
- Remove all
/Literal/
segments from your XPath expressions - If you tested several types of literals, you can e.g. do it like
/*[self::StringLiteral or self::CharLiteral]/
- As is usual, use the designer to explore the new AST structure
- Remove all
- The nodes
ASTPrimaryPrefix
andASTPrimarySuffix
are removed from the grammar. Subtrees for primary expressions appear to be left-recursive now. For example,
new Foo().bar.foo(1)
used to be parsed as
Expression
+ PrimaryExpression
+ PrimaryPrefix
+ AllocationExpression
+ ClassOrInterfaceType[@Image="Foo"]
+ PrimarySuffix
+ Arguments
+ PrimarySuffix
+ Name[@Image="bar.foo"]
+ PrimarySuffix
+ Arguments
+ ArgumentsList
+ Expression
+ PrimaryExpression
+ Literal[@ValueAsInt=1]
It’s now parsed as
MethodCall[@MethodName="foo"]
+ FieldAccess[@FieldName="bar"]
+ ConstructorCall
+ ClassOrInterfaceType[@TypeImage="Foo"]
+ ArgumentsList
+ ArgumentsList
+ NumericLiteral[@ValueAsInt=1]
Instead of being flat, the subexpressions are now nested within one another. The nesting follows the naturally recursive structure of expressions:
new Foo().bar.foo(1)
--------- ConstructorCall
------------- FieldAccess
-------------------- MethodCall
This makes the AST more regular and easier to navigate. Each node contains the other nodes that are relevant to it (e.g. arguments) instead of them being spread out over several siblings. The API of all nodes has been enriched with high-level accessors to query the AST in a semantic way, without bothering with the placement details.
The amount of changes in the grammar that this change entails is enormous, but hopefully firing up the designer to inspect the new structure should give you the information you need quickly.
TODO write a summary of changes in the javadoc of the package, will be more accessible.
Note: this doesn’t affect binary expressions like ASTAdditiveExpression
.
E.g. a+b+c
is not parsed as
AdditiveExpression
+ AdditiveExpression
+ (a)
+ (b)
+ (c)
It’s still
AdditiveExpression
+ (a)
+ (b)
+ (c)
which is easier to navigate, especially from XPath.
Revamped Command Line Interface
PMD now ships with a unified Command Line Interface for both Linux/Unix and Windows. Instead of having a collection
of scripts for the different utilities shipped with PMD, a single script pmd
(pmd.bat
for Windows) can now
launch all utilities using subcommands, e.g. pmd check
, pmd designer
. All commands and options are thoroughly
documented in the help, with full color support where available. Moreover, efforts were made to provide consistency
in the usage of all PMD utilities.
$ Usage: pmd [-hV] [COMMAND]
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
Commands:
check The PMD standard source code analyzer
cpd Copy/Paste Detector - find duplicate code
designer The PMD visual rule designer
cpd-gui GUI for the Copy/Paste Detector
Warning: May not support the full CPD feature set
ast-dump Experimental: dumps the AST of parsing source code
Exit Codes:
0 Successful analysis, no violations found
1 An unexpected error occurred during execution
2 Usage error, please refer to the command help
4 Successful analysis, at least 1 violation found
For instance, where you previously would have run
run.sh pmd -d src -R ruleset.xml
you should now use
pmd check -d src -R ruleset.xml
or even better, omit using -d
/ --dir
and simply pass the sources at the end of the parameter list
pmd check -R ruleset.xml src
Multiple source directories can be passed, such as:
pmd check -R ruleset.xml src/main/java src/test/java
And the exact same applies to CPD:
pmd cpd --minimum-tokens 100 src/main/java
Additionally, the CLI for the check
command has been enhanced with a progress bar, which interactively displays the
current progress of the analysis.
This can be disabled with the --no-progress
flag.
Finally, we now provide a completion script for Bash/Zsh to further help daily usage.
This script can be found under shell/pmd-completion.sh
in the binary distribution.
To use it, edit your ~/.bashrc
/ ~/.zshrc
file and add the following line:
source *path_to_pmd*/shell/pmd-completion.sh
Contributors: Juan MartĂn Sotuyo Dodero (@jsotuyod)
Full Antlr support
PMD 6 only supported JavaCC based grammars, but with Antlr parsers can be generated as well. Languages backed by an Antlr grammar are now fully supported. This means, it’s now possible not only to use Antlr grammars for CPD, but we can actually build full-fledged PMD rules for them as well. Both the traditional Java visitor rules, and the simpler XPath rules are available to users. This allows to leverage existing grammars.
We expect this to enable both our dev team and external contributors to largely extend PMD usage for more languages.
Two languages (Swift and Kotlin) already use this new possibility.
Contributors: Lucas Soncini (@lsoncini), MatĂas Fraga (@matifraga), Tomás De Lucca (@tomidelucca)
Updated PMD Designer
This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.
New CPD report format cpdhtml-v2.xslt
Thanks to @mohan-chinnappan-n a new CPD report format has been added which features a data table. It uses an XSLT stylesheet to convert CPD’s XML format into HTML.
See the example report.
🎉 Language Related Changes
New: Swift support
Given the full Antlr support, PMD now fully supports Swift. We are pleased to announce we are shipping a number of rules starting with PMD 7.
ForceCast
(swift-errorprone
) flags all force casts, making sure you are defensively considering all types. Having the application crash shouldn’t be an option.ForceTry
(swift-errorprone
) flags all force tries, making sure you are defensively handling exceptions. Having the application crash shouldn’t be an option.ProhibitedInterfaceBuilder
(swift-bestpractices
) flags any usage of interface builder. Interface builder files are prone to merge conflicts, and are impossible to code review, so larger teams usually try to avoid it or reduce its usage.UnavailableFunction
(swift-bestpractices
) flags any function throwing afatalError
not marked as@available(*, unavailable)
to ensure no calls are actually performed in the codebase.
Contributors: Lucas Soncini (@lsoncini), MatĂas Fraga (@matifraga), Tomás De Lucca (@tomidelucca)
New: Kotlin support (experimental)
PMD now supports Kotlin as an additional language for analyzing source code. It is based on the official kotlin Antlr grammar. Java-based rules and XPath-based rules are supported.
Kotlin support has experimental stability level, meaning no compatibility should be expected between even incremental releases. Any functionality can be added, removed or changed without warning.
We are shipping the following rules:
FunctionNameTooShort
(kotlin-bestpractices
) finds functions with a too short name.OverrideBothEqualsAndHashcode
(kotlin-errorprone
) finds classes with only eitherequals
orhashCode
overridden, but not both. This leads to unexpected behavior once instances of such classes are used in collections (Lists, HashMaps, …).
Contributors: Jeroen Borgers (@jborgers), Peter Paul Bakker (@stokpop)
New: CPD support for TypeScript
Thanks to a contribution, CPD now supports the TypeScript language. It is shipped
with the rest of the JavaScript support in the module pmd-javascript
.
Contributors: Paul Guyot (@pguyot)
New: CPD support for Julia
Thanks to a contribution, CPD now supports the Julia language. It is shipped
in the new module pmd-julia
.
Contributors: Wener (@wener-tiobe)
New: CPD support for Coco
Thanks to a contribution, CPD now supports Coco, a modern programming language
designed specifically for building event-driven software. It is shipped in the new
module pmd-coco
.
Contributors: Wener (@wener-tiobe)
Changed: JavaScript support
The JS specific parser options have been removed. The parser now always retains comments and uses version ES6. The language module registers a couple of different versions. The latest version, which supports ES6 and also some new constructs (see Rhino]), is the default. This should be fine for most use cases.
Changed: Language versions
We revisited the versions that were defined by each language module. Now many more versions are defined for each language. In general, you can expect that PMD can parse all these different versions. There might be situations where this fails and this can be considered a bug. Usually the latest version is selected as the default language version.
The language versions can be used to mark rules to be useful only for a specific language version via
the minimumLanguageVersion
and maximumLanguageVersion
attributes. While this feature is currently only used by
the Java module, listing all possible versions enables other languages as well to use this feature.
Related issue: [core] Explicitly name all language versions (#4120)
Changed: CPP can now ignore identifiers in sequences (CPD)
- new command line option for CPD:
--ignore-sequences
. - This option is used for CPP only: with the already existing option
--ignore-literal-sequences
, only literals were ignored. The new option additional ignores identifiers as well in sequences. - See PR #4470 for details.
🌟 New and changed rules
New Rules
Apex
UnusedMethod
finds unused methods in your code.
Java
UnnecessaryBoxing
reports boxing and unboxing conversions that may be made implicit.
Kotlin
Swift
Changed Rules
General changes
- All statistical rules (like ExcessiveClassLength, ExcessiveParameterList) have been simplified and unified.
The properties
topscore
andsigma
have been removed. The propertyminimum
is still there, however the type is not a decimal number anymore but has been changed to an integer. This affects rules in the languages Apex, Java, PLSQL and Velocity Template Language (vm):- Apex:
ExcessiveClassLength
,ExcessiveParameterList
,ExcessivePublicCount
,NcssConstructorCount
,NcssMethodCount
,NcssTypeCount
- Java:
ExcessiveImports
,ExcessiveParameterList
,ExcessivePublicCount
,SwitchDensity
- PLSQL:
ExcessiveMethodLength
,ExcessiveObjectLength
,ExcessivePackageBodyLength
,ExcessivePackageSpecificationLength
,ExcessiveParameterList
,ExcessiveTypeLength
,NcssMethodCount
,NcssObjectCount
,NPathComplexity
- VM:
ExcessiveTemplateLength
- Apex:
- The general property
violationSuppressXPath
which is available for all rules to suppress warnings now uses XPath version 3.1 by default. This version of the XPath language is mostly identical to XPath 2.0. In PMD 6, XPath 1.0 has been used. If you upgrade from PMD 6, you need to verify yourviolationSuppressXPath
properties.
Apex General changes
- The properties
cc_categories
,cc_remediation_points_multiplier
,cc_block_highlighting
have been removed from all rules. These properties have been deprecated since PMD 6.13.0. See issue #1648 for more details.
Java General changes
-
Violations reported on methods or classes previously reported the line range of the entire method or class. With PMD 7.0.0, the reported location is now just the identifier of the method or class. This affects various rules, e.g.
CognitiveComplexity
.The report location is controlled by the overrides of the method
getReportLocation
in different node types.See issue #4439 and issue #730 for more details.
Java Best Practices
ArrayIsStoredDirectly
: Violations are now reported on the assignment and not anymore on the formal parameter. The reported line numbers will probably move.AvoidReassigningLoopVariables
: This rule might not report anymore all reassignments of the control variable in for-loops when the propertyforReassign
is set toskip
. See issue #4500 for more details.LooseCoupling
: The rule has a new property to allow some types to be coupled to (allowedTypes
).UnusedLocalVariable
: This rule has some important false-negatives fixed and finds many more cases now. For details see issues #2130, #4516, and #4517.
Java Codestyle
MethodNamingConventions
: The propertycheckNativeMethods
has been removed. The property was deprecated since PMD 6.3.0. Use the propertynativePattern
to control whether native methods should be considered or not.ShortVariable
: This rule now also reports short enum constant names.UseDiamondOperator
: The propertyjava7Compatibility
has been removed. The rule now handles Java 7 properly without a property.UnnecessaryFullyQualifiedName
: The rule has two new properties, to selectively disable reporting on static field and method qualifiers. The rule also has been improved to be more precise.UselessParentheses
: The rule has two new properties which control how strict the rule should be applied. WithignoreClarifying
(default: true) parentheses that are strictly speaking not necessary are allowed, if they separate expressions of different precedence. The other propertyignoreBalancing
(default: true) is similar, in that it allows parentheses that help reading and understanding the expressions.
Java Design
CyclomaticComplexity
: The propertyreportLevel
has been removed. The property was deprecated since PMD 6.0.0. The report level can now be configured separated for classes and methods usingclassReportLevel
andmethodReportLevel
instead.ImmutableField
: The propertyignoredAnnotations
has been removed. The property was deprecated since PMD 6.52.0.LawOfDemeter
: The rule has a new propertytrustRadius
. This defines the maximum degree of trusted data. The default of 1 is the most restrictive.NPathComplexity
: The propertyminimum
has been removed. It was deprecated since PMD 6.0.0. Use the propertyreportLevel
instead.SingularField
: The propertiescheckInnerClasses
anddisallowNotAssignment
have been removed. The rule is now more precise and will check these cases properly.UseUtilityClass
: The propertyignoredAnnotations
has been removed.
Java Documentation
CommentContent
: The propertiescaseSensitive
anddisallowedTerms
are removed. The new propertyforbiddenRegex
can be used now to define the disallowed terms with a single regular expression.CommentRequired
:- Overridden methods are now detected even without the
@Override
annotation. This is relevant for the propertymethodWithOverrideCommentRequirement
. See also pull request #3757. - Elements in annotation types are now detected as well. This might lead to an increased number of violations for missing public method comments.
- Overridden methods are now detected even without the
CommentSize
: When determining the line-length of a comment, the leading comment prefix markers (e.g.*
or//
) are ignored and don’t add up to the line-length. See also pull request #4369.
Java Error Prone
AvoidDuplicateLiterals
: The propertyexceptionfile
has been removed. The property was deprecated since PMD 6.10.0. Use the propertyexceptionList
instead.DontImportSun
:sun.misc.Signal
is not special-cased anymore.EmptyCatchBlock
:CloneNotSupportedException
andInterruptedException
are not special-cased anymore. Rename the exception parameter toignored
to ignore them.ImplicitSwitchFallThrough
: Violations are now reported on the case statements rather than on the switch statements. This is more accurate but might result in more violations now.
Deprecated Rules
In PMD 7.0.0, there are now deprecated rules.
Removed Rules
The following previously deprecated rules have been finally removed:
Apex
- performance.xml/AvoidSoqlInLoops (deleted) -> use
OperationWithLimitsInLoop
- performance.xml/AvoidSoslInLoops (deleted) -> use
OperationWithLimitsInLoop
- performance.xml/AvoidDmlStatementsInLoops (deleted) -> use
OperationWithLimitsInLoop
Java
- codestyle.xml/AbstractNaming (deleted) -> use
ClassNamingConventions
- AvoidFinalLocalVariable (java-codestyle) -> not replaced
- AvoidPrefixingMethodParameters (java-codestyle) -> use
FormalParameterNamingConventions
- AvoidUsingShortType (java-performance) -> not replaced
- BadComparison (java-errorprone) -> use
ComparisonWithNaN
- BeanMembersShouldSerialize (java-errorprone) -> use
NonSerializableClass
- BooleanInstantiation (java-performance) -> use
UnnecessaryBoxing
andPrimitiveWrapperInstantiation
- ByteInstantiation (java-performance) -> use
UnnecessaryBoxing
andPrimitiveWrapperInstantiation
- CloneThrowsCloneNotSupportedException (java-errorprone) -> not replaced
- DataflowAnomalyAnalysis (java-errorprone) -> use
UnusedAssignment
- DefaultPackage (java-codestyle) -> use
CommentDefaultAccessModifier
- DoNotCallSystemExit (java-errorprone) -> use
DoNotTerminateVM
- DontImportJavaLang (java-codestyle) -> use
UnnecessaryImport
- DuplicateImports (java-codestyle) -> use
UnnecessaryImport
- EmptyFinallyBlock (java-errorprone) -> use
EmptyControlStatement
- EmptyIfStmt (java-errorprone) -> use
EmptyControlStatement
- EmptyInitializer (java-errorprone) -> use
EmptyControlStatement
- EmptyStatementBlock (java-errorprone) -> use
EmptyControlStatement
- EmptyStatementNotInLoop (java-errorprone) -> use
UnnecessarySemicolon
- EmptySwitchStatements (java-errorprone) -> use
EmptyControlStatement
- EmptySynchronizedBlock (java-errorprone) -> use
EmptyControlStatement
- EmptyTryBlock (java-errorprone) -> use
EmptyControlStatement
- EmptyWhileStmt (java-errorprone) -> use
EmptyControlStatement
- ExcessiveClassLength (java-design) -> use
NcssCount
- ExcessiveMethodLength (java-design) -> use
NcssCount
- ForLoopsMustUseBraces (java-codestyle) -> use
ControlStatementBraces
- IfElseStmtsMustUseBraces (java-codestyle) -> use
ControlStatementBraces
- IfStmtsMustUseBraces (java-codestyle) -> use
ControlStatementBraces
- ImportFromSamePackage (java-errorprone) -> use
UnnecessaryImport
- IntegerInstantiation (java-performance) -> use
UnnecessaryBoxing
andPrimitiveWrapperInstantiation
- InvalidSlf4jMessageFormat (java-errorprone) -> use
InvalidLogMessageFormat
- LoggerIsNotStaticFinal (java-errorprone) -> use
ProperLogger
- LongInstantiation (java-performance) -> use
UnnecessaryBoxing
andPrimitiveWrapperInstantiation
- MIsLeadingVariableName (java-codestyle) -> use
FieldNamingConventions
,FormalParameterNamingConventions
, orLocalVariableNamingConventions
- MissingBreakInSwitch (java-errorprone) -> use
ImplicitSwitchFallThrough
- ModifiedCyclomaticComplexity (java-design) -> use
CyclomaticComplexity
- NcssConstructorCount (java-design) -> use
NcssCount
- NcssMethodCount (java-design) -> use
NcssCount
- NcssTypeCount (java-design) -> use
NcssCount
- PositionLiteralsFirstInCaseInsensitiveComparisons (java-bestpractices) ->
use
LiteralsFirstInComparisons
- PositionLiteralsFirstInComparisons (java-bestpractices) ->
use
LiteralsFirstInComparisons
- ReturnEmptyArrayRatherThanNull (java-errorprone) ->
use
ReturnEmptyCollectionRatherThanNull
- ShortInstantiation (java-performance) -> use
UnnecessaryBoxing
andPrimitiveWrapperInstantiation
- SimplifyBooleanAssertion (java-design) -> use
SimplifiableTestAssertion
- SimplifyStartsWith (java-performance) -> not replaced
- StdCyclomaticComplexity (java-design) -> use
CyclomaticComplexity
- SuspiciousConstantFieldName (java-codestyle) -> use
FieldNamingConventions
- UnnecessaryWrapperObjectCreation (java-performance) -> use the new rule
UnnecessaryBoxing
- UnsynchronizedStaticDateFormatter (java-multithreading) ->
use
UnsynchronizedStaticFormatter
- UnusedImports (java-bestpractices) -> use
UnnecessaryImport
- UseAssertEqualsInsteadOfAssertTrue (java-bestpractices) ->
use
SimplifiableTestAssertion
- UseAssertNullInsteadOfAssertEquals (java-bestpractices) ->
use
SimplifiableTestAssertion
- UseAssertSameInsteadOfAssertEquals (java-bestpractices) ->
use
SimplifiableTestAssertion
- UseAssertTrueInsteadOfAssertEquals (java-bestpractices) ->
use
SimplifiableTestAssertion
- VariableNamingConventions (apex-codestyle) -> use
FieldNamingConventions
,FormalParameterNamingConventions
,LocalVariableNamingConventions
, orPropertyNamingConventions
- VariableNamingConventions (java-codestyle) -> use
FieldNamingConventions
,FormalParameterNamingConventions
, orLocalVariableNamingConventions
- WhileLoopsMustUseBraces (java-codestyle) -> use
ControlStatementBraces
đź’Ą Compatibility and Migration Notes
For endusers
- PMD 7 requires Java 8 or above to execute.
- CLI changed: Custom scripts need to be updated (
run.sh pmd ...
->pmd check ...
,run.sh cpd ...
,pmd cpd ...
). - Java module revamped: Custom rules need to be updated.
- Removed rules: Custom rulesets need to be reviewed. See below for a list of new and removed rules.
- XPath 1.0 support is removed,
violationSuppressXPath
now requires XPath 2.0 or 3.1: Custom rulesets need to be reviewed. - Custom rules using rulechains: Need to override
buildTargetSelector
usingforTypes
. -
The asset filenames of PMD on GitHub Releases are now
pmd-dist-<version>-bin.zip
,pmd-dist-<version>-src.zip
andpmd-dist-<version>-doc.zip
. Keep that in mind, if you have an automated download script.The structure inside the ZIP files stay the same, e.g. we still provide inside the binary distribution ZIP file the base directory
pmd-bin-<version>
.
For integrators
- PMD 7 is a major release where many things have been moved or rewritten.
- All integrators will require some level of change to adapt to the change in the API.
- For more details look at the deprecations notes of the past PMD 6 releases.
- The PMD Ant tasks, which were previously in the module
pmd-core
has been moved into its own modulepmd-ant
- The CLI classes have also been moved out of
pmd-core
into its own modulepmd-cli
. The old entry point, the main classPMD
is gone.
🚨 API
The API of PMD has been growing over the years and needed some cleanup. The goal is, to have a clear separation between a well-defined API and the implementation, which is internal. This should help us in future development.
This however entails some incompatibilities and deprecations, see also the sections New API support guidelines and API removals below.
New API support guidelines
Until now, all released public members and types were implicitly considered part of PMD’s public API, including inheritance-specific members (protected members, abstract methods). We have maintained those APIs with the goal to preserve full binary compatibility between minor releases, only breaking those APIs infrequently, for major releases.
In order to allow PMD to move forward at a faster pace, this implicit contract will be invalidated with PMD 7.0.0. We now introduce more fine-grained distinctions between the type of compatibility support we guarantee for our libraries, and ways to make them explicit to clients of PMD.
.internal
packages and @InternalApi
annotation
Internal API is meant for use only by the main PMD codebase. Internal types and methods may be modified in any way, or even removed, at any time.
Any API in a package that contains an .internal
segment is considered internal.
The @InternalApi
annotation will be used for APIs that have to live outside of
these packages, e.g. methods of a public type that shouldn’t be used outside of PMD (again,
these can be removed anytime).
@ReservedSubclassing
Types marked with the @ReservedSubclassing
annotation are only meant to be subclassed
by classes within PMD. As such, we may add new abstract methods, or remove protected methods,
at any time. All published public members remain supported. The annotation is not inherited, which
means a reserved interface doesn’t prevent its implementors to be subclassed.
@Experimental
APIs marked with the @Experimental
annotation at the class or method level are subject to change.
They can be modified in any way, or even removed, at any time. You should not use or rely
on them in any production code. They are purely to allow broad testing and feedback.
@Deprecated
APIs marked with the @Deprecated
annotation at the class or method level will remain supported
until the next major release, but it is recommended to stop using them.
Small Changes and cleanups
-
#1648: [apex,vf] Remove CodeClimate dependency - Robert Sösemann Properties “cc_categories”, “cc_remediation_points_multiplier”, “cc_block_highlighting” can no longer be overridden in rulesets. They were deprecated without replacement.
-
The old GUI applications accessible through
run.sh designerold
andrun.sh bgastviewer
(and corresponding Batch scripts) have been removed from the PMD distribution. Please use the newer rule designer withpmd designer
. The corresponding classes in packagesjava.net.sourceforge.pmd.util.viewer
andjava.net.sourceforge.pmd.util.designer
have all been removed. -
All API related to XPath support has been moved to the package
net.sourceforge.pmd.lang.rule.xpath
. This includes API that was previously dispersed overnet.sourceforge.pmd.lang
,net.sourceforge.pmd.lang.ast.xpath
,net.sourceforge.pmd.lang.rule.xpath
,net.sourceforge.pmd.lang.rule
, and various language-specific packages (which were made internal). -
The implementation of the Ant integration has been moved from the module
pmd-core
to a new modulepmd-ant
. This involves classes in packagenet.sourceforge.pmd.ant
. The ant CPDTask classnet.sourceforge.pmd.cpd.CPDTask
has been moved into the same packagenet.sourceforge.pmd.ant
. You’ll need to update your taskdef entries in your build.xml files with the FQCNnet.sourceforge.pmd.ant.CPDTask
if you use it anywhere. -
Utility classes in
net.sourceforge.pmd.util
, that have previously marked as@InternalApi
have been finally moved tonet.sourceforge.pmd.internal.util
. This includes ClasspathClassLoader, FileFinder, FileUtil, and IOUtil. - The following utility classes in
net.sourceforge.pmd.util
are now considered public API: - Moved the two classes
AntlrTokenizer
andJavaCCTokenizer
frominternal
package into packagenet.sourceforge.pmd.cpd.impl
. These two classes are part of the API and are base classes for CPD language implementations. Since 7.0.0-rc2. AntlrBaseRule
is gone in favor ofAbstractVisitorRule
. Since 7.0.0-rc2.- The classes
KotlinInnerNode
andSwiftInnerNode
are package-private now. Since 7.0.0-rc2.
XPath 3.1 support
Support for XPath versions 1.0, 1.0-compatibility was removed, support for XPath 2.0 is deprecated. The default (and only) supported XPath version is now XPath 3.1. This version of the XPath language is mostly identical to XPath 2.0.
Notable changes:
- The deprecated support for sequence-valued attributes is removed. Sequence-valued properties are still supported.
- Refer to the Saxonica documentation for an introduction to new features in XPath 3.1.
Node stream API for AST traversal
This version includes a powerful API to navigate trees, similar in usage to the Java 8 Stream API:
node.descendants(ASTMethodCall.class)
.filter(m -> "toString".equals(m.getMethodName()))
.map(m -> m.getQualifier())
.filter(q -> TypeTestUtil.isA(String.class, q))
.foreach(System.out::println);
A pipeline like shown here traverses the tree lazily, which is more efficient than traversing eagerly to put all descendants in a list. It is also much easier to change than the old imperative way.
To make this API as accessible as possible, the Node
interface has been fitted with new
methods producing node streams. Those methods replace previous tree traversal methods like Node#findDescendantsOfType
.
In all cases, they should be more efficient and more convenient.
See NodeStream
for more details.
Contributors: Clément Fournier (@oowekyala)
Metrics framework
The metrics framework has been made simpler and more general.
-
The metric interface takes an additional type parameter, representing the result type of the metric. This is usually
Integer
orDouble
. It avoids widening the result to adouble
just to narrow it down.This makes it so, that
Double.NaN
is not an appropriate sentinel value to represent “not supported” anymore. Instead,computeFor
may returnnull
in that case (or a garbage value). The valuenull
may have caused problems with the narrowing casts, which through unboxing, might have thrown an NPE. But when we deprecated the language-specific metrics façades to replace them with the genericMetricsUtil
, we took care of making the new methods throw an exception if the metric cannot be computed on the parameter. This forces you to guard calls toMetricsUtil::computeMetric
with something likeif (metric.supports(node))
. If you’re following this pattern, then you won’t observe the undefined behavior. -
The
MetricKey
interface is not so useful and has been merged into theMetric
interface and removed. So theMetric
interface has the new methodString name()
. -
The framework is not tied to at most 2 node types per language anymore. Previously those were nodes for classes and for methods/constructors. Instead, many metrics support more node types. For example, NCSS can be computed on any code block.
For that reason, keeping around a hard distinction between “class metrics” and “operation metrics” is not useful. So in the Java framework for example, we removed the interfaces
JavaClassMetric
,JavaOperationMetric
, abstract classes for those,JavaClassMetricKey
, andJavaOperationMetricKey
. Metric constants are now all inside theJavaMetrics
utility class. The same was done in the Apex framework.We don’t really need abstract classes for metrics now. So
AbstractMetric
is also removed from pmd-core. There is a factory method on theMetric
interface to create a metric easily. -
This makes it so, that
LanguageMetricsProvider
does not need type parameters. It can just return aSet<Metric<?, ?>>
to list available metrics. -
Signature
s, their implementations, and the interfaceSignedNode
have been removed. Node streams allow replacing their usages very easily.
Testing framework
- PMD 7 has been upgraded to use JUnit 5 only. That means, that JUnit4 related classes have been removed, namely
net.sourceforge.pmd.testframework.PMDTestRunner
net.sourceforge.pmd.testframework.RuleTestRunner
net.sourceforge.pmd.testframework.TestDescriptor
- Rule tests, that use
SimpleAggregatorTst
orPmdRuleTst
work as before without change, but use now JUnit5 under the hood. If you added additional JUnit4 tests to your rule test classes, then you’ll need to upgrade them to use JUnit5.
Language Lifecycle and Language Properties
- Language modules now provide a proper lifecycle and can store global information. This enables the implementation of multifile analysis.
- Language modules can define custom language properties which can be set via environment variables. This allows to add and use language specific configuration options without the need to change pmd-core.
The documentation page has been updated: Adding a new language with JavaCC and Adding a new language with ANTLR
Related issue: [core] Language lifecycle (#3782)
API changes
7.0.0-rc3
- The following previously deprecated classes have been removed:
- pmd-core
net.sourceforge.pmd.PMD
net.sourceforge.pmd.cli.PMDCommandLineInterface
net.sourceforge.pmd.cli.PMDParameters
net.sourceforge.pmd.cli.PmdParametersParseResult
- pmd-core
-
The asset filenames of PMD on GitHub Releases are now
pmd-dist-<version>-bin.zip
,pmd-dist-<version>-src.zip
andpmd-dist-<version>-doc.zip
. Keep that in mind, if you have an automated download script.The structure inside the ZIP files stay the same, e.g. we still provide inside the binary distribution ZIP file the base directory
pmd-bin-<version>
. - The CLI option
--stress
(or-stress
) has been removed without replacement. - The CLI option
--minimum-priority
was changed with 7.0.0-rc1 to only take the following values: High, Medium High, Medium, Medium Low, Low. With 7.0.0-rc2 compatibility has been restored, so that the equivalent integer values (1 to 5) are supported as well. -
Replaced
RuleViolation::getFilename
with newRuleViolation#getFileId
, that returns aFileId
. This is an identifier for aTextFile
and could represent a path name. This allows to have a separate display name, e.g. renderers useFileNameRenderer
to either display the full path name or a relative path name (seeRenderer#setFileNameRenderer
andConfigurableFileNameRenderer
). Many places where we used a simple String for a path-like name before have been adapted to use the newFileId
.See PR #4425 for details.
7.0.0-rc2
- The following previously deprecated classes have been removed:
- pmd-core
net.sourceforge.pmd.PMD
net.sourceforge.pmd.cli.PMDCommandLineInterface
net.sourceforge.pmd.cli.PMDParameters
net.sourceforge.pmd.cli.PmdParametersParseResult
- pmd-core
- The CLI option
--minimum-priority
was changed with 7.0.0-rc1 to only take the following values: High, Medium High, Medium, Medium Low, Low. With 7.0.0-rc2 compatibility has been restored, so that the equivalent integer values (1 to 5) are supported as well.
7.0.0-rc1
- The CLI option
--stress
(or-stress
) has been removed without replacement. - The CLI option
--minimum-priority
now takes one of the following values instead of an integer: High, Medium High, Medium, Medium Low, Low.
6.55.0
Go
- The LanguageModule of Go, that only supports CPD execution, has been deprecated. This language is not fully supported by PMD, so having a language module does not make sense. The functionality of CPD is not affected by this change. The following class has been deprecated and will be removed with PMD 7.0.0:
Java
- Support for Java 18 preview language features have been removed. The version “18-preview” is no longer available.
- The experimental class
net.sourceforge.pmd.lang.java.ast.ASTGuardedPattern
has been removed.
6.54.0
PMD CLI
- PMD now supports a new
--relativize-paths-with
flag (or short-z
), which replaces--short-names
. It serves the same purpose: Shortening the pathnames in the reports. However, with the new flag it’s possible to explicitly define one or more pathnames that should be used as the base when creating relative paths. The old flag--short-names
is deprecated.
Deprecated APIs
For removal
ApexRootNode#getApexVersion
has been deprecated for removal. The version returned is alwaysVersion.CURRENT
, as the apex compiler integration doesn’t use additional information which Apex version actually is used. Therefore, this method can’t be used to determine the Apex version of the project that is being analyzed.CPDConfiguration#setEncoding
andCPDConfiguration#getEncoding
. Use the methodsgetSourceEncoding
andsetSourceEncoding
instead. Both are available forCPDConfiguration
which extendsAbstractConfiguration
.BaseCLITest
andBaseCPDCLITest
have been deprecated for removal without replacement. CLI tests should be done in pmd-core only (and in PMD7 in pmd-cli). Individual language modules shouldn’t need to test the CLI integration logic again. Instead, the individual language modules should test their functionality as unit tests.-
FileCollector#addZipFile
has been deprecated. It is replaced byFileCollector#addZipFileWithContent
which directly adds the content of the zip file for analysis. PMDConfiguration#setReportShortNames
andPMDConfiguration#isReportShortNames
have been deprecated for removal. UsePMDConfiguration#addRelativizeRoot
instead.
Internal APIs
CSVWriter
- Some fields in
AbstractAntTestHelper
Experimental APIs
- CPDReport has a new method which limited mutation of a given report:
filterMatches
creates a new CPD report with some matches removed with a given predicate based filter.
6.53.0
Deprecated APIs
For removal
These classes / APIs have been deprecated and will be removed with PMD 7.0.0.
ExcessiveLengthRule
(Java)
6.52.0
PMD CLI
-
PMD now supports a new
--use-version
flag, which receives a language-version pair (such asjava-8
orapex-54
). This supersedes the usage of-language
/-l
and-version
/-v
, allowing for multiple versions to be set in a single run. PMD 7 will completely remove support for-language
and-version
in favor of this new flag. -
Support for
-V
is being deprecated in favor of--verbose
in preparation for PMD 7. In PMD 7,-v
will enable verbose mode and-V
will show the PMD version for consistency with most Unix/Linux tools. -
Support for
-min
is being deprecated in favor of--minimum-priority
for consistency with most Unix/Linux tools, where-min
would be equivalent to-m -i -n
.
CPD CLI
- CPD now supports using
-d
or--dir
as an alias to--files
, in favor of consistency with PMD. PMD 7 will remove support for--files
in favor of these new flags.
Linux run.sh parameters
-
Using
run.sh cpdgui
will now warn about it being deprecated. Userun.sh cpd-gui
instead. -
The old designer (
run.sh designerold
) is completely deprecated and will be removed in PMD 7. Switch to the new JavaFX designer:run.sh designer
. -
The old visual AST viewer (
run.sh bgastviewer
) is completely deprecated and will be removed in PMD 7. Switch to the new JavaFX designer:run.sh designer
for a visual tool, or userun.sh ast-dump
for a text-based alternative.
Deprecated API
- The following core APIs have been marked as deprecated for removal in PMD 7:
PMD
andStatusCode
- PMD 7 will ship with a revamped CLI split from pmd-core. To programmatically launch analysis you can usePmdAnalysis
.PMDConfiguration#getAllInputPaths
- It is now superseded byPMDConfiguration#getInputPathList
PMDConfiguration#setInputPaths
- It is now superseded byPMDConfiguration#setInputPathList
PMDConfiguration#addInputPath
- It is now superseded byPMDConfiguration#addInputPath
PMDConfiguration#getInputFilePath
- It is now superseded byPMDConfiguration#getInputFile
PMDConfiguration#getIgnoreFilePath
- It is now superseded byPMDConfiguration#getIgnoreFile
PMDConfiguration#setInputFilePath
- It is now superseded byPMDConfiguration#setInputFilePath
PMDConfiguration#setIgnoreFilePath
- It is now superseded byPMDConfiguration#setIgnoreFilePath
PMDConfiguration#getInputUri
- It is now superseded byPMDConfiguration#getUri
PMDConfiguration#setInputUri
- It is now superseded byPMDConfiguration#setInputUri
PMDConfiguration#getReportFile
- It is now superseded byPMDConfiguration#getReportFilePath
PMDConfiguration#setReportFile
- It is now superseded byPMDConfiguration#setReportFile
PMDConfiguration#isStressTest
andPMDConfiguration#setStressTest
- Will be removed with no replacement.PMDConfiguration#isBenchmark
andPMDConfiguration#setBenchmark
- Will be removed with no replacement, the CLI will still support it.CPD
andCPD.StatusCode
- PMD 7 will ship with a revamped CLI split from pmd-core. An alterative to programatically launch CPD analysis will be added in due time.
- In order to reduce the dependency on Apex Jorje classes, the method
DataType#fromBasicType
has been deprecated. The equivalent methodfromTypeName
should be used instead.
6.51.0
No changes.
6.50.0
CPD CLI
- CPD now supports the
--ignore-literal-sequences
argument when analyzing Lua code.
6.49.0
Deprecated API
- In order to reduce the dependency on Apex Jorje classes, the following methods have been deprecated.
These methods all leaked internal Jorje enums. These enums have been replaced now by enums the
PMD’s AST package.
ASTAssignmentExpression#getOperator
ASTBinaryExpression#getOperator
ASTBooleanExpression#getOperator
ASTPostfixExpression#getOperator
ASTPrefixExpression#getOperator
All these classes have now a new
getOp()
method. Existing code should be refactored to use this method instead. It returns the new enums, likeAssignmentOperator
, and avoids the dependency to Jorje.
6.48.0
CPD CLI
- CPD has a new CLI option
--debug
. This option has the same behavior as in PMD. It enables more verbose logging output.
Rule Test Framework
- The module “pmd-test”, which contains support classes to write rule tests, now requires Java 8. If you depend on this module for testing your own custom rules, you’ll need to make sure to use at least Java 8.
- The new module “pmd-test-schema” contains now the XSD schema and the code to parse the rule test XML files. The schema has been extracted in order to easily share it with other tools like the Rule Designer or IDE plugins.
- Test schema changes:
- The attribute
isRegressionTest
oftest-code
is deprecated. The new attributedisabled
should be used instead for defining whether a rule test should be skipped or not. - The attributes
reinitializeRule
anduseAuxClasspath
oftest-code
are deprecated and assumed true. They will not be replaced. - The new attribute
focused
oftest-code
allows disabling all tests except the focused one temporarily.
- The attribute
- More information about the rule test framework can be found in the documentation: Testing your rules
Deprecated API
- The experimental Java AST class
ASTGuardedPattern
has been deprecated and will be removed. It was introduced for Java 17 and Java 18 Preview as part of pattern matching for switch, but it is no longer supported with Java 19 Preview. - The interface
CPDRenderer
is deprecated. For custom CPD renderers the new interfaceCPDReportRenderer
should be used. - The class
TestDescriptor
is deprecated, replaced withRuleTestDescriptor
. - Many methods of
RuleTst
have been deprecated as internal API.
Experimental APIs
- To support the Java preview language features “Pattern Matching for Switch” and “Record Patterns”, the following AST nodes have been introduced as experimental:
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.
CPDConfiguration#setRenderer
CPDConfiguration#setCPDRenderer
CPDConfiguration#getRenderer
CPDConfiguration#getCPDRenderer
CPDConfiguration#getRendererFromString
CPDConfiguration#getCPDRendererFromString
CPDRendererAdapter
6.47.0
No changes.
6.46.0
Deprecated ruleset references
Ruleset references with the following formats are now deprecated and will produce a warning when used on the CLI or in a ruleset XML file:
<lang-name>-<ruleset-name>
, egjava-basic
, which resolves torulesets/java/basic.xml
- the internal release number, eg
600
, which resolves torulesets/releases/600.xml
Use the explicit forms of these references to be compatible with PMD 7.
Deprecated API
toString
is now deprecated. The format of this method will remain the same until PMD 7. The deprecation is intended to steer users away from relying on this format, as it may be changed in PMD 7.getInputPaths
andsetInputPaths
are now deprecated. A new set of methods have been added, which use lists and do not rely on comma splitting.
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.
CPDCommandLineInterface
has been internalized. In order to execute CPD eitherCPD#run
orCPD#main
should be used.- Several members of
BaseCPDCLITest
have been deprecated with replacements. - The methods
Formatter#start
,Formatter#end
,Formatter#getRenderer
, andFormatter#isNoOutputSupplied
have been internalized.
6.45.0
Experimental APIs
- Report has two new methods which allow limited mutations of a given report:
Report#filterViolations
creates a new report with some violations removed with a given predicate based filter.Report#union
can combine two reports into a single new Report.
net.sourceforge.pmd.util.Predicate
will be replaced in PMD7 with the standard Predicate interface from java8.- The module
pmd-html
is entirely experimental right now. Anything in the packagenet.sourceforge.pmd.lang.html
should be used cautiously.
6.44.0
Deprecated API
- Several members of
PMD
have been newly deprecated, including:PMD#EOL
: useSystem#lineSeparator()
PMD#SUPPRESS_MARKER
: useDEFAULT_SUPPRESS_MARKER
PMD#processFiles
: use the new programmatic APIPMD#getApplicableFiles
: is internal
PMDConfiguration#prependClasspath
is deprecated in favour ofprependAuxClasspath
.PMDConfiguration#setRuleSets
andgetRuleSets
are deprecated. Use insteadsetRuleSets
,addRuleSet
, andgetRuleSetPaths
.- Several members of
BaseCLITest
have been deprecated with replacements. -
Several members of
PMDCommandLineInterface
have been explicitly deprecated. The whole class however was deprecated long ago already with 6.30.0. It is internal API and should not be used. - In modelica, the rule classes
AmbiguousResolutionRule
andConnectUsingNonConnector
have been deprecated, since they didn’t comply to the usual rule class naming conventions yet. The replacements are in the subpackagebestpractices
.
Experimental APIs
-
Together with the new programmatic API the interface
TextFile
has been added as experimental. It intends to replaceDataSource
andSourceCode
in the long term.This interface will change in PMD 7 to support read/write operations and other things. You don’t need to use it in PMD 6, as
FileCollector
decouples you from this. A file collector is available throughPmdAnalysis#files
.
6.43.0
Deprecated API
Some API deprecations were performed in core PMD classes, to improve compatibility with PMD 7.
Report
: the constructor and other construction methods like addViolation or createReportRuleContext
: all constructors, getters and setters. A new set of stable methods, matching those in PMD 7, was added to replace theaddViolation
overloads ofAbstractRule
. In PMD 7,RuleContext
will be the API to report violations, and it can already be used as such in PMD 6.- The field
configuration
is unused and will be removed.
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.
RuleSet
: methods that serve to apply rules, includingapply
,start
,end
,removeDysfunctionalRules
AbstractAccumulatingRenderer#renderFileReport
is internal API and should not be overridden in own renderers.
Changed API
It is now forbidden to report a violation:
- With a
null
node - With a
null
message - With a
null
set of format arguments (prefer a zero-length array)
Note that the message is set from the XML rule declaration, so this is only relevant if you instantiate rules manually.
RuleContext
now requires setting the current rule before calling
apply
. This is
done automatically by RuleSet#apply
and such. Creating and configuring a
RuleContext
manually is strongly advised against, as the lifecycle of RuleContext
will change drastically in PMD 7.
6.42.0
No changes.
6.41.0
Command Line Interface
The command line options for PMD and CPD now use GNU-syle long options format. E.g. instead of -rulesets
the
preferred usage is now --rulesets
. Alternatively one can still use the short option -R
.
Some options also have been renamed to a more consistent casing pattern at the same time
(--fail-on-violation
instead of -failOnViolation
).
The old single-dash options are still supported but are deprecated and will be removed with PMD 7.
This change makes the command line interface more consistent within PMD and also less surprising
compared to other cli tools.
The changes in detail for PMD:
old option | new option |
---|---|
-rulesets |
--rulesets (or -R ) |
-uri |
--uri |
-dir |
--dir (or -d ) |
-filelist |
--file-list |
-ignorelist |
--ignore-list |
-format |
--format (or -f ) |
-debug |
--debug |
-verbose |
--verbose |
-help |
--help |
-encoding |
--encoding |
-threads |
--threads |
-benchmark |
--benchmark |
-stress |
--stress |
-shortnames |
--short-names |
-showsuppressed |
--show-suppressed |
-suppressmarker |
--suppress-marker |
-minimumpriority |
--minimum-priority |
-property |
--property |
-reportfile |
--report-file |
-force-language |
--force-language |
-auxclasspath |
--aux-classpath |
-failOnViolation |
--fail-on-violation |
--failOnViolation |
--fail-on-violation |
-norulesetcompatibility |
--no-ruleset-compatibility |
-cache |
--cache |
-no-cache |
--no-cache |
The changes in detail for CPD:
old option | new option |
---|---|
--failOnViolation |
--fail-on-violation |
-failOnViolation |
--fail-on-violation |
--filelist |
--file-list |
6.40.0
Experimental APIs
- The interface
ASTCommentContainer
has been added to the Apex AST. It provides a way to check whether a node contains at least one comment. Currently this is only implemented forASTCatchBlockStatement
and used by the ruleEmptyCatchBlock
. This information is also available via XPath attribute@ContainsComment
.
6.39.0
No changes.
6.38.0
No changes.
6.37.0
PMD CLI
-
PMD has a new CLI option
-force-language
. With that a language can be forced to be used for all input files, irrespective of filenames. When using this option, the automatic language selection by extension is disabled and all files are tried to be parsed with the given language. Parsing errors are ignored and unparsable files are skipped.This option allows to use the xml language for files, that don’t use xml as extension. See also the examples on PMD CLI reference.
Experimental APIs
- The AST types and APIs around Sealed Classes are not experimental anymore:
ASTClassOrInterfaceDeclaration#isSealed
,ASTClassOrInterfaceDeclaration#isNonSealed
,ASTClassOrInterfaceDeclaration#getPermittedSubclasses
ASTPermitsList
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.
- The inner class
net.sourceforge.pmd.cpd.TokenEntry.State
is considered to be internal API. It will probably be moved away with PMD 7.
6.36.0
No changes.
6.35.0
Deprecated API
PMD#doPMD
is deprecated. UsePMD#runPMD
instead.PMD#run
is deprecated. UsePMD#runPMD
instead.ThreadSafeReportListener
and the methods to use them inReport
(addListener
,getListeners
,addListeners
) are deprecated. This functionality will be replaced by another TBD mechanism in PMD 7.
6.34.0
No changes.
6.33.0
No changes.
6.32.0
Experimental APIs
- The experimental class
ASTTypeTestPattern
has been renamed toASTTypePattern
in order to align the naming to the JLS. - The experimental class
ASTRecordConstructorDeclaration
has been renamed toASTCompactConstructorDeclaration
in order to align the naming to the JLS. - The AST types and APIs around Pattern Matching and Records are not experimental anymore:
ASTVariableDeclaratorId#isPatternBinding
ASTPattern
ASTTypePattern
ASTRecordDeclaration
ASTRecordComponentList
ASTRecordComponent
ASTRecordBody
ASTCompactConstructorDeclaration
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.
- The protected or public member of the Java rule
AvoidUsingHardCodedIPRule
are deprecated and considered to be internal API. They will be removed with PMD 7.
6.31.0
Deprecated API
AbstractDomXmlRule
AbstractWsdlRule
- A few methods of
AbstractXmlRule
Experimental APIs
- The method
GenericToken#getKind
has been added as experimental. This unifies the token interface for both JavaCC and Antlr. The already existing methodAntlrToken#getKind
is therefore experimental as well. The returned constant depends on the actual language and might change whenever the grammar of the language is changed.
6.30.0
Deprecated API
Around RuleSet parsing
RuleSetFactory
andRulesetsFactoryUtils
have been deprecated in favor ofRuleSetLoader
. This is easier to configure, and more maintainable than the multiple overloads ofRulesetsFactoryUtils
.- Some static creation methods have been added to
RuleSet
for simple cases, egforSingleRule
. These replace some counterparts inRuleSetFactory
- Since
RuleSets
is also deprecated, many APIs that require a RuleSets instance now are deprecated, and have a counterpart that expects aList<RuleSet>
. RuleSetReferenceId
,RuleSetReference
,RuleSetFactoryCompatibility
are deprecated. They are most likely not relevant outside of the implementation of pmd-core.
Around the PMD
class
Many classes around PMD’s entry point (PMD
) have been deprecated as internal, including:
- The contents of the packages
net.sourceforge.pmd.cli
,net.sourceforge.pmd.processor
SourceCodeProcessor
- The constructors of
PMD
(the class will be made a utility class)
Miscellaneous
ASTPackageDeclaration#getPackageNameImage
,ASTTypeParameter#getParameterName
and the corresponding XPath attributes. In both cases they’re replaced with a new methodgetName
, the attribute is@Name
.ASTClassOrInterfaceBody#isAnonymousInnerClass
, andASTClassOrInterfaceBody#isEnumChild
, refs #905
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.
net.sourceforge.pmd.lang.ecmascript.Ecmascript3Handler
net.sourceforge.pmd.lang.ecmascript.Ecmascript3Parser
EcmascriptParser#parserOptions
EcmascriptParser#getSuppressMap
net.sourceforge.pmd.lang.rule.ParametricRuleViolation
ParserOptions#suppressMarker
net.sourceforge.pmd.lang.modelica.rule.ModelicaRuleViolationFactory
6.29.0
No changes.
6.28.0
Deprecated API
For removal
net.sourceforge.pmd.RuleViolationComparator
. UseRuleViolation#DEFAULT_COMPARATOR
instead.net.sourceforge.pmd.cpd.AbstractTokenizer
. Usenet.sourceforge.pmd.cpd.AnyTokenizer
instead.net.sourceforge.pmd.cpd.FortranTokenizer
. Was replaced by anAnyTokenizer
. UseFortranLanguage#getTokenizer
anyway.net.sourceforge.pmd.cpd.PerlTokenizer
. Was replaced by anAnyTokenizer
. UsePerlLanguage#getTokenizer
anyway.net.sourceforge.pmd.cpd.RubyTokenizer
. Was replaced by anAnyTokenizer
. UseRubyLanguage#getTokenizer
anyway.RuleReference#getOverriddenLanguage
andRuleReference#setLanguage
- Antlr4 generated lexers:
net.sourceforge.pmd.lang.cs.antlr4.CSharpLexer
will be moved to packagenet.sourceforge.pmd.lang.cs.ast
with PMD 7.net.sourceforge.pmd.lang.dart.antlr4.Dart2Lexer
will be renamed toDartLexer
and moved to packagenet.sourceforge.pmd.lang.dart.ast
with PMD 7. All other classes in the old package will be removed.net.sourceforge.pmd.lang.go.antlr4.GolangLexer
will be moved to packagenet.sourceforge.pmd.lang.go.ast
with PMD 7. All other classes in the old package will be removed.net.sourceforge.pmd.lang.kotlin.antlr4.Kotlin
will be renamed toKotlinLexer
and moved to packagenet.sourceforge.pmd.lang.kotlin.ast
with PMD 7.net.sourceforge.pmd.lang.lua.antlr4.LuaLexer
will be moved to packagenet.sourceforge.pmd.lang.lua.ast
with PMD 7. All other classes in the old package will be removed.
6.27.0
- XML rule definition in rulesets: In PMD 7, the
language
attribute will be required on allrule
elements that declare a new rule. Some base rule classes set the language implicitly in their constructor, and so this is not required in all cases for the rule to work. But this behavior will be discontinued in PMD 7, so missinglanguage
attributes are now reported as a forward compatibility warning.
Deprecated API
For removal
Rule#getParserOptions
Parser#getParserOptions
AbstractParser
RuleContext#removeAttribute
RuleContext#getAttribute
RuleContext#setAttribute
ApexParserOptions
ASTThrowStatement#getFirstClassOrInterfaceTypeImage
EcmascriptParserOptions
EcmascriptXPathRule
XmlParserOptions
XmlXPathRule
-
Properties of
AbstractXmlRule
net.sourceforge.pmd.Report.ReadableDuration
-
Many methods of
net.sourceforge.pmd.Report
. They are replaced by accessors that produce a List. For example,iterator()
(and implementing Iterable) andisEmpty()
are both replaced bygetViolations()
. - The dataflow codebase is deprecated for removal in PMD 7. This includes all code in the following packages, and their subpackages:
net.sourceforge.pmd.lang.plsql.dfa
net.sourceforge.pmd.lang.java.dfa
net.sourceforge.pmd.lang.dfa
-
and the class
PLSQLDataFlowHandler
ASTJspDeclarations
ASTJspDocument
ScalaParserVisitorAdapter#zero
ScalaParserVisitorAdapter#combine
ApexParserVisitorReducedAdapter
TypeHelper
is deprecated in favor ofTypeTestUtil
, which has the same functionality, but a slightly changed API.- Many of the classes in
net.sourceforge.pmd.lang.java.symboltable
are deprecated as internal API.
6.26.0
Deprecated API
For removal
RuleChainVisitor
and all implementations in language modulesAbstractRuleChainVisitor
Language#getRuleChainVisitorClass
BaseLanguageModule#<init>
ImportWrapper
6.25.0
-
The maven module
net.sourceforge.pmd:pmd-scala
is deprecated. Usenet.sourceforge.pmd:pmd-scala_2.13
ornet.sourceforge.pmd:pmd-scala_2.12
instead. -
Rule implementation classes are internal API and should not be used by clients directly. The rules should only be referenced via their entry in the corresponding category ruleset (e.g.
<rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod" />
).While we definitely won’t move or rename the rule classes in PMD 6.x, we might consider changes in PMD 7.0.0 and onwards.
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.
AbstractIgnoredAnnotationRule
(Java)AbstractInefficientZeroCheck
(Java)AbstractJUnitRule
(Java)AbstractJavaMetricsRule
(Java)AbstractLombokAwareRule
(Java)AbstractPoorMethodCall
(Java)AbstractSunSecureRule
(Java)AbstractNcssCountRule
(Java)AbstractCommentRule
(Java)AbstractOptimizationRule
(Java)RegexHelper
(Java)AbstractApexUnitTestRule
(Apex)AbstractNcssCountRule
(Apex)AbstractNcssCountRule
(PLSQL)ApexParser
ApexHandler
RuleChain
RuleSets
RulesetsFactoryUtils#getRuleSets
For removal
TokenEntry#TokenEntry
AbstractTokenizerTest
. Use CpdTextComparisonTest in module pmd-lang-test instead. For details see Testing your implementation in the developer documentation.ASTAnnotation#suppresses
(Apex)ApexXPathRule
(Apex)SymbolTableTestRule
(Java)InefficientStringBufferingRule#isInStringBufferOperation
6.24.0
Deprecated APIs
BaseLanguageModule#addVersion(String, LanguageVersionHandler, boolean)
- Some members of
TokenMgrError
, in particular, a new constructor is available that should be preferred to the old ones ANTLRSyntaxError
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.
6.23.0
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
orNode
, 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
(egVfParser
) are deprecated and should not be used directly. UseLanguageVersionHandler#getParser
instead. - The implementation classes of
TokenManager
(egVfTokenManager
) 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.
- Apex:
net.sourceforge.pmd.lang.apex.ast
- Javascript:
net.sourceforge.pmd.lang.ecmascript.ast
- PL/SQL:
net.sourceforge.pmd.lang.plsql.ast
- Scala:
net.sourceforge.pmd.lang.scala.ast
- Visualforce:
net.sourceforge.pmd.lang.vf.ast
These deprecations have already been rolled out in a previous version for the following languages:
- Java:
net.sourceforge.pmd.lang.java.ast
- Java Server Pages:
net.sourceforge.pmd.lang.jsp.ast
- Velocity Template Language:
net.sourceforge.pmd.lang.vm.ast
Outside of these packages, these changes also concern the following TokenManager implementations, and their corresponding Parser if it exists (in the same package):
CppTokenManager
JavaTokenManager
Ecmascript5TokenManager
JspTokenManager
MatlabTokenManager
ModelicaTokenManager
ObjectiveCTokenManager
PLSQLTokenManager
PythonTokenManager
VfTokenManager
VmTokenManager
In the Java AST the following attributes are deprecated and will issue a warning when used in XPath rules:
ASTAdditiveExpression#getImage
- usegetOperator()
insteadASTVariableDeclaratorId#getImage
- usegetName()
insteadASTVariableDeclaratorId#getVariableName
- usegetName()
instead
For removal
Parser#getTokenManager
TokenManager#setFileName
AbstractTokenManager#setFileName
AbstractTokenManager#getFileName
AntlrToken#getType
- usegetKind()
instead.ImmutableLanguage
MockRule
Node#getFirstParentOfAnyType
Node#getAsDocument
AbstractNode#hasDescendantOfAnyType
ASTRecordDeclaration#getComponentList
- Multiple fields, constructors and methods in
XPathRule
. See javadoc for details.
6.22.0
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
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
orNode
, 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. 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
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
orNode
, 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 classesDirectiveMapper
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 as ASTCursorSpecification
.
6.21.0
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. 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 ofParseException
, whose usages will be replaced by just that superclass.
For removal
- pmd-core
- Many methods on the
Node
interface andAbstractNode
base class. See their javadoc for details. Node#isFindBoundary
is deprecated for XPath queries.
- Many methods on the
- 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.
6.20.0
No changes.
6.19.0
Deprecated APIs
For removal
- pmd-core
- All the package
net.sourceforge.pmd.dcd
and its subpackages. SeeDCD
. - In
LanguageRegistry
: RuleSet#getExcludePatterns
. Use the new methodgetFileExclusions
instead.RuleSet#getIncludePatterns
. Use the new methodgetFileInclusions
instead.Parser#canParse
Parser#getSuppressMap
RuleBuilder#RuleBuilder
. Use the new constructor with the correct ResourceLoader instead.RuleFactory#RuleFactory
. Use the new constructor with the correct ResourceLoader instead.
- All the package
- pmd-java
CanSuppressWarnings
and its implementationsisSuppressed
getDeclaringType
.isSupressed
ASTMethodDeclarator
getMethodName
getBlock
getParameterCount
- pmd-apex
CanSuppressWarnings
and its implementationsisSupressed
Internal APIs
- pmd-core
- All the package
net.sourceforge.pmd.util
and its subpackages, exceptnet.sourceforge.pmd.util.datasource
andnet.sourceforge.pmd.util.database
. GridBagHelper
ColumnDescriptor
- All the package
6.18.0
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 methodAbstractRenderer#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
- The methods
getImportedNameNode
andgetPackage
have been deprecated and will be removed with PMD 7.0.0. - The method
RuleContext#setSourceCodeFilename
has been deprecated and will be removed. The already existing methodRuleContext#setSourceCodeFile
should be used instead. The methodRuleContext#getSourceCodeFilename
still exists and returns just the filename without the full path. - The method
AbstractPMDProcessor#filenameFrom
has been deprecated. It was used to determine a “short name” of the file being analyzed, so that the report can use short names. However, this logic has been moved to the renderers. - The method
Report#metrics
andReport
have been deprecated. They were leftovers from a previous deprecation round targetingStatisticalRule
.
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.
- pmd-core
- pmd-java
net.sourceforge.pmd.lang.java.typeresolution
: Everything, including subpackages, exceptTypeHelper
andJavaTypeDefinition
.ASTCompilationUnit#getClassTypeResolver
6.17.0
No changes.
6.16.0
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.
- 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.
6.15.0
Deprecated APIs
For removal
- The
DumpFacades
in all languages, that could be used to transform a AST into a textual representation, will be removed with PMD 7. The rule designer is a better way to inspect nodes. net.sourceforge.pmd.lang.apex.ast.DumpFacade
net.sourceforge.pmd.lang.java.ast.DumpFacade
net.sourceforge.pmd.lang.ecmascript.ast.DumpFacade
net.sourceforge.pmd.lang.jsp.ast.DumpFacade
net.sourceforge.pmd.lang.plsql.ast.DumpFacade
net.sourceforge.pmd.lang.vf.ast.DumpFacade
net.sourceforge.pmd.lang.vm.ast.AbstractVmNode#dump
net.sourceforge.pmd.lang.xml.ast.DumpFacade
- The method
LanguageVersionHandler#getDumpFacade
will be removed as well. It is deprecated, along with all its implementations in the subclasses ofLanguageVersionHandler
.
6.14.0
No changes.
6.13.0
Command Line Interface
The start scripts run.sh
, pmd.bat
and cpd.bat
support the new environment variable PMD_JAVA_OPTS
.
This can be used to set arbitrary JVM options for running PMD, such as memory settings (e.g. PMD_JAVA_OPTS=-Xmx512m
)
or enable preview language features (e.g. PMD_JAVA_OPTS=--enable-preview
).
The previously available variables such as OPTS
or HEAPSIZE
are deprecated and will be removed with PMD 7.0.0.
Deprecated API
-
CodeClimateRule
is deprecated in 7.0.0 because it was unused for 2 years and created an unwanted dependency. Properties “cc_categories”, “cc_remediation_points_multiplier”, “cc_block_highlighting” will also be removed. See #1702 for more. -
The Apex ruleset
rulesets/apex/ruleset.xml
has been deprecated and will be removed in 7.0.0. Please use the new quickstart rulesetrulesets/apex/quickstart.xml
instead.
6.12.0
No changes.
6.11.0
StatisticalRule
and the related helper classes and base rule classes are deprecated for removal in 7.0.0. This includes all ofnet.sourceforge.pmd.stat
andnet.sourceforge.pmd.lang.rule.stat
, and alsoAbstractStatisticalJavaRule
,AbstractStatisticalApexRule
and the like. The methodsReport#addMetric
andmetricAdded
will also be removed.setProperty
is deprecated, becauseMultiValuePropertyDescriptor
is deprecated as well
6.10.0
Properties framework
The properties framework is about to get a lifting, and for that reason, we need to deprecate a lot of APIs to remove them in 7.0.0. The proposed changes to the API are described on the wiki
Changes to how you define properties
-
Construction of property descriptors has been possible through builders since 6.0.0. The 7.0.0 API will only allow construction through builders. The builder hierarchy, currently found in the package
net.sourceforge.pmd.properties.builders
, is being replaced by the simplerPropertyBuilder
. Their APIs enjoy a high degree of source compatibility. -
Concrete property classes like
IntegerProperty
andStringMultiProperty
will gradually all be deprecated until 7.0.0. Their usages should be replaced by direct usage of thePropertyDescriptor
interface, e.g.PropertyDescriptor<Integer>
orPropertyDescriptor<List<String>>
. -
Instead of spreading properties across countless classes, the utility class
PropertyFactory
will become from 7.0.0 on the only provider for property descriptor builders. Each current property type will be replaced by a corresponding method onPropertyFactory
:IntegerProperty
is replaced byPropertyFactory#intProperty
IntegerMultiProperty
is replaced byPropertyFactory#intListProperty
FloatProperty
andDoubleProperty
are both replaced byPropertyFactory#doubleProperty
. Having a separate property for floats wasn’t that useful.- Similarly,
FloatMultiProperty
andDoubleMultiProperty
are replaced byPropertyFactory#doubleListProperty
.
- Similarly,
StringProperty
is replaced byPropertyFactory#stringProperty
StringMultiProperty
is replaced byPropertyFactory#stringListProperty
-
RegexProperty
is replaced byPropertyFactory#regexProperty
EnumeratedProperty
is replaced byPropertyFactory#enumProperty
EnumeratedProperty
is replaced byPropertyFactory#enumListProperty
BooleanProperty
is replaced byPropertyFactory#booleanProperty
- Its multi-valued counterpart,
BooleanMultiProperty
, is not replaced, because it doesn’t have a use case.
- Its multi-valued counterpart,
CharacterProperty
is replaced byPropertyFactory#charProperty
CharacterMultiProperty
is replaced byPropertyFactory#charListProperty
LongProperty
is replaced byPropertyFactory#longIntProperty
LongMultiProperty
is replaced byPropertyFactory#longIntListProperty
MethodProperty
,FileProperty
,TypeProperty
and their multi-valued counterparts are discontinued for lack of a use-case, and have no planned replacement in 7.0.0 for now.
Here’s an example:
// Before 7.0.0, these are equivalent:
IntegerProperty myProperty = new IntegerProperty("score", "Top score value", 1, 100, 40, 3.0f);
IntegerProperty myProperty = IntegerProperty.named("score").desc("Top score value").range(1, 100).defaultValue(40).uiOrder(3.0f);
// They both map to the following in 7.0.0
PropertyDescriptor<Integer> myProperty = PropertyFactory.intProperty("score").desc("Top score value").require(inRange(1, 100)).defaultValue(40);
You’re highly encouraged to migrate to using this new API as soon as possible, to ease your migration to 7.0.0.
Architectural simplifications
-
EnumeratedPropertyDescriptor
,NumericPropertyDescriptor
,PackagedPropertyDescriptor
, and the related builders (innet.sourceforge.pmd.properties.builders
) will be removed. These specialized interfaces allowed additional constraints to be enforced on the value of a property, but made the property class hierarchy very large and impractical to maintain. Their functionality will be mapped uniformly toPropertyConstraint
s, which will allow virtually any constraint to be defined, and improve documentation and error reporting. The related methodsPropertyTypeId#isPropertyNumeric
andPropertyTypeId#isPropertyPackaged
are also deprecated. -
MultiValuePropertyDescriptor
andSingleValuePropertyDescriptor
are deprecated. 7.0.0 will introduce a new XML syntax which will remove the need for such a divide between single- and multi-valued properties. The methodPropertyDescriptor#isMultiValue
will be removed accordingly.
Changes to the PropertyDescriptor interface
preferredRowCount
is deprecated with no intended replacement. It was never implemented, and does not belong in this interface. The methodsuiOrder
andcompareTo(PropertyDescriptor)
are deprecated for the same reason. These methods mix presentation logic with business logic and are not necessary for PropertyDescriptors to work.PropertyDescriptor
will not extendComparable<PropertyDescriptor>
anymore come 7.0.0.- The method
propertyErrorFor
is deprecated and will be removed with no intended replacement. It’s really just a shortcut forprop.errorFor(rule.getProperty(prop))
. T
valueFrom(String)
andString
asDelimitedString
(T)
are deprecated and will be removed. These were used to serialize and deserialize properties to/from a string, but 7.0.0 will introduce a more flexible XML syntax which will make them obsolete.isMultiValue
andtype
are deprecated and won’t be replaced. The new XML syntax will remove the need for a divide between multi- and single-value properties, and will allow arbitrary types to be represented. Since arbitrary types may be represented,type
will become obsolete as it can’t represent generic types, which will nevertheless be representable with the XML syntax. It was only used for documentation, but a new way to document these properties exhaustively will be added with 7.0.0.errorFor
is deprecated as its return type will be changed toOptional<String>
with the shift to Java 8.
Deprecated APIs
For internalization
-
The implementation of the adapters for the XPath engines Saxon and Jaxen (package
net.sourceforge.pmd.lang.ast.xpath
) are now deprecated. They’ll be moved to an internal package come 7.0.0. OnlyAttribute
remains public API. -
The classes
PropertyDescriptorField
,PropertyDescriptorBuilderConversionWrapper
, and the methodsPropertyDescriptor#attributeValuesById
,PropertyDescriptor#isDefinedExternally
andPropertyTypeId#getFactory
. These were used to read and write properties to and from XML, but were not intended as public API. -
The class
ValueParserConstants
and the interfaceValueParser
. -
All classes from
net.sourceforge.pmd.lang.java.metrics.impl.visitors
are now considered internal API. They’re deprecated and will be moved into an internal package with 7.0.0. To implement your own metrics visitors,JavaParserVisitorAdapter
should be directly subclassed. -
LanguageVersionHandler#getDataFlowHandler()
,LanguageVersionHandler#getDFAGraphRule()
For removal
-
All classes from
net.sourceforge.pmd.properties.modules
will be removed. -
The interface
Dimensionable
has been deprecated. It gets in the way of a grammar change for 7.0.0 and won’t be needed anymore (see #997). -
Several methods from
ASTLocalVariableDeclaration
andASTFieldDeclaration
have also been deprecated: -
ASTFieldDeclaration
won’t be aTypeNode
come 7.0.0, sogetType
andgetTypeDefinition
are deprecated. -
The method
getVariableName
on those two nodes will be removed, too.
All these are deprecated because those nodes may declare several variables at once, possibly
with different types (and obviously with different names). They both implement `Iterator<`<a href="https://docs.pmd-code.org/apidocs/pmd-java/7.0.0-rc3/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.html#"><code>ASTVariableDeclaratorId</code></a>`>`
though, so you should iterate on each declared variable. See [#910](https://github.com/pmd/pmd/issues/910).
-
Visitor decorators are now deprecated and will be removed in PMD 7.0.0. They were originally a way to write composable visitors, used in the metrics framework, but they didn’t prove cost-effective.
-
In
net.sourceforge.pmd.lang.java.ast
:JavaParserDecoratedVisitor
,JavaParserControllessVisitor
,JavaParserControllessVisitorAdapter
, andJavaParserVisitorDecorator
are deprecated with no intended replacement. -
The LanguageModules of several languages, that only support CPD execution, have been deprecated. These languages are not fully supported by PMD, so having a language module does not make sense. The functionality of CPD is not affected by this change. The following classes have been deprecated and will be removed with PMD 7.0.0:
CppHandler
CppLanguageModule
CppParser
CsLanguageModule
FortranLanguageModule
GroovyLanguageModule
MatlabHandler
MatlabLanguageModule
MatlabParser
ObjectiveCHandler
ObjectiveCLanguageModule
ObjectiveCParser
PhpLanguageModule
PythonHandler
PythonLanguageModule
PythonParser
RubyLanguageModule
ScalaLanguageModule
- Optional AST processing stages like symbol table, type resolution or data-flow analysis will be reified
in 7.0.0 to factorise common logic and make them extensible. Further explanations about this change can be
found on #1426. Consequently, the following APIs are deprecated for
removal:
- In
Rule
:isDfa()
,isTypeResolution()
,isMultifile()
and their respective setters. - In
RuleSet
:usesDFA(Language)
,usesTypeResolution(Language)
,usesMultifile(Language)
- In
RuleSets
:usesDFA(Language)
,usesTypeResolution(Language)
,usesMultifile(Language)
- In
LanguageVersionHandler
:getDataFlowFacade()
,getSymbolFacade()
,getSymbolFacade(ClassLoader)
,getTypeResolutionFacade(ClassLoader)
,getQualifiedNameResolutionFacade(ClassLoader)
- In
6.9.0
No changes.
6.8.0
-
A couple of methods and fields in
net.sourceforge.pmd.properties.AbstractPropertySource
have been deprecated, as they are replaced by already existing functionality or expose internal implementation details:propertyDescriptors
,propertyValuesByDescriptor
,copyPropertyDescriptors()
,copyPropertyValues()
,ignoredProperties()
,usesDefaultValues()
,useDefaultValueFor()
. -
Some methods in
net.sourceforge.pmd.properties.PropertySource
have been deprecated as well:usesDefaultValues()
,useDefaultValueFor()
,ignoredProperties()
. -
The class
net.sourceforge.pmd.lang.rule.AbstractDelegateRule
has been deprecated and will be removed with PMD 7.0.0. It is internally only in use by RuleReference. -
The default constructor of
net.sourceforge.pmd.lang.rule.RuleReference
has been deprecated and will be removed with PMD 7.0.0. RuleReferences should only be created by providing a Rule and a RuleSetReference. Furthermore the following methods are deprecated:setRuleReference()
,hasOverriddenProperty()
,usesDefaultValues()
,useDefaultValueFor()
.
6.7.0
-
All classes in the package
net.sourceforge.pmd.lang.dfa.report
have been deprecated and will be removed with PMD 7.0.0. This includes the classnet.sourceforge.pmd.lang.dfa.report.ReportTree
. The reason is, that this class is very specific to Java and not suitable for other languages. It has only been used forYAHTMLRenderer
, which has been rewritten to work without these classes. -
The nodes RUNSIGNEDSHIFT and RSIGNEDSHIFT are deprecated and will be removed from the AST with PMD 7.0.0. These represented the operator of ShiftExpression in two cases out of three, but they’re not needed and make ShiftExpression inconsistent. The operator of a ShiftExpression is now accessible through ShiftExpression#getOperator.
6.5.0
-
The utility class
net.sourceforge.pmd.lang.java.ast.CommentUtil
has been deprecated and will be removed with PMD 7.0.0. Its methods have been intended to parse javadoc tags. A more useful solution will be added around the AST nodeFormalComment
, which contains as childrenJavadocElement
nodes, which in turn provide access to theJavadocTag
.All comment AST nodes (
FormalComment
,MultiLineComment
,SingleLineComment
) have a new methodgetFilteredComment()
which provide access to the comment text without the leading/*
markers. -
The method
AbstractCommentRule.tagsIndicesIn()
has been deprecated and will be removed with PMD 7.0.0. It is not very useful, since it doesn’t extract the information in a useful way. You would still need check, which tags have been found, and with which data they might be accompanied.
6.4.0
- The following classes in package
net.sourceforge.pmd.benchmark
have been deprecated:Benchmark
,Benchmarker
,BenchmarkReport
,BenchmarkResult
,RuleDuration
,StringBuilderCR
andTextReport
. Their API is not supported anymore and is disconnected from the internals of PMD. Use the newer API based aroundTimeTracker
instead, which can be found in the same package. - The class
net.sourceforge.pmd.lang.java.xpath.TypeOfFunction
has been deprecated. Use the newerTypeIsFunction
in the same package. - The
typeof
methods innet.sourceforge.pmd.lang.java.xpath.JavaFunctions
have been deprecated. Use the newertypeIs
method in the same class instead.. - The methods
isA
,isEither
andisNeither
ofnet.sourceforge.pmd.lang.java.typeresolution.TypeHelper
. Use the newisExactlyAny
andisExactlyNone
methods in the same class instead.
6.2.0
-
The static method
PMDParameters.transformParametersIntoConfiguration(PMDParameters)
is now deprecated, for removal in 7.0.0. The new instance methodPMDParameters.toConfiguration()
replaces it. -
The method
ASTConstructorDeclaration.getParameters()
has been deprecated in favor of the new methodgetFormalParameters()
. This method is available for bothASTConstructorDeclaration
andASTMethodDeclaration
.
6.1.0
- The method
getXPathNodeName
is added to theNode
interface, which removes the use of thetoString
of a node to get its XPath element name (see #569).- The default implementation provided in
AbstractNode
, will be removed with 7.0.0 - With 7.0.0, the
Node.toString
method will not necessarily provide its XPath node name anymore.
- The default implementation provided in
-
The interface
net.sourceforge.pmd.cpd.Renderer
has been deprecated. A new interfacenet.sourceforge.pmd.cpd.renderer.CPDRenderer
has been introduced to replace it. The main difference is that the new interface is meant to render directly to ajava.io.Writer
rather than to a String. This allows to greatly reduce the memory footprint of CPD, as on large projects, with many duplications, it was causingOutOfMemoryError
s (see #795).net.sourceforge.pmd.cpd.FileReporter
has also been deprecated as part of this change, as it’s no longer needed.
6.0.1
- The constant
net.sourceforge.pmd.PMD.VERSION
has been deprecated and will be removed with PMD 7.0.0. Please usenet.sourceforge.pmd.PMDVersion.VERSION
instead.