Releases: pmd/pmd
PMD 6.26.0 (25-July-2020)
25-July-2020 - 6.26.0
The PMD team is pleased to announce PMD 6.26.0.
This is a minor release.
Table Of Contents
New and noteworthy
New Rules
- The new Java rule
UnusedAssignment
(java-bestpractices
) finds assignments
to variables, that are never used and are useless. The new rule is supposed to entirely replace
DataflowAnomalyAnalysis
.
Modified rules
- The Java rule
ArrayIsStoredDirectly
(java-bestpractices
) now ignores
by default private methods and constructors. You can restore the old behavior by setting the new property
allowPrivate
to "false".
Fixed Issues
- apex
- #2610: [apex] Support top-level enums in rules
- apex-bestpractices
- #2626: [apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex
- apex-performance
- #2598: [apex] AvoidSoqlInLoops false positive for SOQL with in For-Loop
- apex-security
- #2620: [visualforce] False positive on VfUnescapeEl with new Message Channel feature
- core
- java-bestpractices
- java-codestyle
- #2546: [java] DuplicateImports reported for the same import... and import static...
- java-design
- #2174: [java] LawOfDemeter: False positive with 'this' pointer
- #2181: [java] LawOfDemeter: False positive with indexed array access
- #2189: [java] LawOfDemeter: False positive when casting to derived class
- #2580: [java] AvoidThrowingNullPointerException marks all NullPointerException objects as wrong, whether or not thrown
- #2625: [java] NPathComplexity can't handle switch expressions
- java-errorprone
- java-performance
API Changes
Deprecated API
For removal
RuleChainVisitor
and all implementations in language modulesAbstractRuleChainVisitor
Language#getRuleChainVisitorClass
BaseLanguageModule#<init>
ImportWrapper
External Contributions
- #2558: [java] Fix issue #1736 and issue #2207 - Young Chan
- #2560: [java] Fix false positives of LawOfDemeter: this and cast expressions - xioayuge
- #2590: Update libraries snyk is referring to as
unsafe
- Artem Krosheninnikov - #2597: [dependencies] Fix issue #2594, update exec-maven-plugin everywhere - Artem Krosheninnikov
- #2621: [visualforce] add new safe resource for VfUnescapeEl - Peter Chittum
- #2640: [java] NullPointerException in rule ProperCloneImplementation - Mykhailo Palahuta
- #2641: [java] AvoidThrowingNullPointerException marks all NullPointerException… - Mykhailo Palahuta
- #2643: [java] AvoidCallingFinalize detects some false positives (2578) - Mykhailo Palahuta
- #2651: [java] False negative: LiteralsFirstInComparisons for methods... (2569) - Mykhailo Palahuta
- #2652: [java] UseCollectionIsEmpty can not detect the case this.foo.size() - Mykhailo Palahuta
Stats
- 156 commits
- 43 closed tickets & PRs
- Days since last release: 28
PMD 6.25.0 (27-June-2020)
27-June-2020 - 6.25.0
The PMD team is pleased to announce PMD 6.25.0.
This is a minor release.
Table Of Contents
New and noteworthy
Scala cross compilation
Up until now the PMD Scala module has been compiled against scala 2.13 only by default.
However, this makes it impossible to use pmd as a library in scala projects,
that use scala 2.12, e.g. in sbt plugins. Therefore PMD now provides cross compiled pmd-scala
modules for both versions: scala 2.12 and scala 2.13.
The new modules have new maven artifactIds. The old artifactId net.sourceforge.pmd:pmd-scala:6.25.0
is still available, but is deprecated from now on. It has been demoted to be just a delegation to the new
pmd-scala_2.13
module and will be removed eventually.
The coordinates for the new modules are:
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-scala_2.12</artifactId>
<version>6.25.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-scala_2.13</artifactId>
<version>6.25.0</version>
</dependency>
The command line version of PMD continues to use scala 2.13.
New Rules
-
The new Java Rule
UnnecessaryCast
(java-codestyle
)
finds casts that are unnecessary while accessing collection elements. -
The new Java Rule
AvoidCalendarDateCreation
(java-performance
)
finds usages ofjava.util.Calendar
whose purpose is just to get the current date. This
can be done in a more lightweight way. -
The new Java Rule
UseIOStreamsWithApacheCommonsFileItem
(java-performance
)
finds usage ofFileItem.get()
andFileItem.getString()
. These two methods are problematic since
they load the whole uploaded file into memory.
Modified rules
-
The Java rule
UseDiamondOperator
(java-codestyle
) now by default
finds unnecessary usages of type parameters, which are nested, involve wildcards and are used
within a ternary operator. These usages are usually only unnecessary with Java8 and later, when
the type inference in Java has been improved.In order to avoid false positives when checking Java7 only code, the rule has the new property
java7Compatibility
, which is disabled by default. Settings this to "true" retains
the old rule behaviour.
Fixed Issues
- apex-bestpractices
- #2554: [apex] Exception applying rule UnusedLocalVariable on trigger
- core
- #971: [apex][plsql][java] Deprecate overly specific base rule classes
- #2451: [core] Deprecate support for List attributes with XPath 2.0
- #2599: [core] Fix XPath 2.0 Rule Chain Analyzer with Unions
- #2483: [lang-test] Support cpd tests based on text comparison.
For details see
Testing your implementation
in the developer documentation.
- c#
- #2551: [c#] CPD suppression with comments doesn't work
- cpp
- #1757: [cpp] Support unicode characters
- java
- #2549: [java] Auxclasspath in PMD CLI does not support relative file path
- java-codestyle
- java-design
- java-errorprone
- #2544: [java] UseProperClassLoader can not detect the case with method call on intermediate variable
- java-performance
- scala
- #2547: [scala] Add cross compilation for scala 2.12 and 2.13
API Changes
-
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
PMD 6.24.0 (24-May-2020)
24-May-2020 - 6.24.0
The PMD team is pleased to announce PMD 6.24.0.
This is a minor release.
Table Of Contents
New and noteworthy
CPD now supports XML as well
Thanks to Fernando Cosso CPD can now find duplicates in XML files as well.
This is useful to find duplicated sections in XML files.
Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
For the changes, see PMD Designer Changelog.
New Rules
-
The new Java Rule
LiteralsFirstInComparisons
(java-bestpractices
)
find String literals, that are used in comparisons and are not positioned first. Using the String literal
as the receiver of e.g.equals
helps to avoid NullPointerExceptions.This rule is replacing the two old rules
PositionLiteralsFirstInComparisons
andPositionLiteralsFirstInCaseInsensitiveComparisons
and extends the check
for the methodscompareTo
,compareToIgnoreCase
andcontentEquals
in addition toequals
and
equalsIgnoreCase
.Note: This rule also replaces the two mentioned rules in Java's quickstart ruleset.
Deprecated Rules
- The two Java rules
PositionLiteralsFirstInComparisons
andPositionLiteralsFirstInCaseInsensitiveComparisons
have been deprecated
in favor of the new ruleLiteralsFirstInComparisons
.
Fixed Issues
- apex-bestpractices
- #2468: [apex] Unused Local Variable fails on blocks
- core
- c#
- #2495: [c#] Support for interpolated verbatim strings
- java
- #2472: [java] JavaCharStream throws an Error on invalid escape
- java-bestpractices
- #2145: [java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons
- #2288: [java] JUnitTestsShouldIncludeAssert: Add support for Hamcrest MatcherAssert.assertThat
- #2437: [java] AvoidPrintStackTrace can't detect the case e.getCause().printStackTrace()
- java-codestyle
- #2476: [java] MethodNamingConventions - Add support for JUnit 5 method naming
- java-errorprone
- #2477: [java] JUnitSpelling false-positive for JUnit5/4 tests
- swift
- #2473: [swift] Swift 5 (up to 5.2) support for CPD
API Changes
Deprecated APIs
BaseLanguageModule#addVersion(String, LanguageVersionHandler, boolean)
- Some members of
TokenMgrError
, in particular, a new constructor is available
that should be preferred to the old ones AntlrTokenManager.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.
External Contributions
- #2446: [core] Update maven-compiler-plugin to 3.8.1 - Artem Krosheninnikov
- #2448: [java] Operator Wrap check - Harsh Kukreja
- #2449: [plsql] Additional info in SqlStatement, FormalParameter and FetchStatement - Grzegorz Sudolski
- #2452: [doc] Fix "Making Rulesets" doc sample code indentation - Artur Dryomov
- #2457: [xml] Adding XML to CPD supported languages - Fernando Cosso
- #2465: [dependencies] Upgrade hamcrest, mockito and JUnit - Artem Krosheninnikov
- #2469: [apex] fix false positive unused variable if only a method is called - Gwilym Kuiper
- #2475: [swift] Swift 4.2-5.2 support - kenji21
- #2476: [java] MethodNamingConventions - Add support for JUnit 5 method naming - Bruno Ritz
- #2478: [java] New rule: LiteralsFirstInComparisons - John-Teng
- #2479: [java] False positive with Hamcrest's assertThat - andreoss
- #2481: [java] Fix JUnitSpellingRule false positive - Artem Krosheninnikov
- #2493: [java] Deprecate redundant String Comparison rules - John-Teng
- #2495: [c#] Support for interpolated verbatim strings - Maikel Steneker
Stats
- 114 commits
- 29 closed tickets & PRs
- Days since last release: 30
PMD 6.23.0 (24-April-2020)
24-April-2020 - 6.23.0
The PMD team is pleased to announce PMD 6.23.0.
This is a minor release.
Table Of Contents
New and noteworthy
PMD adopts Contributor Code of Conduct
To facilitate healthy and constructive community behavior PMD adopts
Contributor Convenant as its code of
conduct.
Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms.
You can find the code of conduct in the file code_of_conduct.md
in our repository.
Performance improvements for XPath 2.0 rules
XPath rules written with XPath 2.0 now support conversion to a rulechain rule, which
improves their performance. The rulechain is a mechanism that allows several rules
to be executed in a single tree traversal. Conversion to the rulechain is possible if
your XPath expression looks like //someNode/... | //someOtherNode/... | ...
, that
is, a union of one or more path expressions that start with //
. Instead of traversing
the whole tree once per path expression (and per rule), a single traversal executes all
rules in your ruleset as needed.
This conversion is performed automatically and cannot be disabled. The conversion should
not change the result of your rules, if it does, please report a bug at https://github.com/pmd/pmd/issues
Note that XPath 1.0 support, the default XPath version, is deprecated since PMD 6.22.0.
We highly recommend that you upgrade your rules to XPath 2.0. Please refer to the migration guide.
Javascript improvements for ES6
PMD uses the Rhino library to parse Javascript.
The default version has been set to ES6
, so that some ECMAScript 2015 features are
supported. E.g. let
statements and for-of
loops are now parsed. However Rhino does
not support all features.
New JSON renderer
PMD now supports a JSON renderer (use it with -f json
on the CLI).
See the documentation and example
New Rules
-
The new Apex rule
FieldDeclarationsShouldBeAtStart
(apex-codestyle
)
helps to ensure that field declarations are always at the beginning of a class. -
The new Apex rule
UnusedLocalVariable
(apex-bestpractices
) detects unused
local variables.
Fixed Issues
- apex-design
- #2358: [apex] Invalid Apex in Cognitive Complexity tests
- apex-security
- core
- doc
- java
- #2378: [java] AbstractJUnitRule has bad performance on large code bases
- java-bestpractices
- #2398: [java] AbstractClassWithoutAbstractMethod false negative with inner abstract classes
- java-codestyle
- java-design
- #2390: [java] AbstractClassWithoutAnyMethod: missing violation for nested classes
- java-errorprone
- #2402: [java] CloseResource possible false positive with Primitive Streams
- java-multithreading
- #2313: [java] Documenation for DoNotUseThreads is outdated
- javascript
- javascript-errorprone
- #384: [javascript] Trailing commas not detected on French default locale
API Changes
Deprecated APIs
Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the @InternalApi
annotation. You'll also get a deprecation warning.
In ASTs
As part of the changes we'd like to do to AST classes for 7.0.0, we would like to
hide some methods and constructors that rule writers should not have access to.
The following usages are now deprecated in the Apex, Javascript, PL/SQL, Scala and Visualforce ASTs:
- Manual instantiation of nodes. Constructors of node classes are deprecated and
markedInternalApi
. Nodes should only be obtained from the parser,
which for rules, means that they never need to instantiate node themselves.
Those constructors will be made package private with 7.0.0. - Subclassing of abstract node classes, or usage of their type. The base classes are internal API
and will be hidden in version 7.0.0. You should not couple your code to them. - Setters found in any node class or interface. Rules should consider the AST immutable.
We will make those setters package private with 7.0.0. - The 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: **<a href="https://docs.pmd-...
PMD 6.22.0 (12-March-2020)
12-March-2020 - 6.22.0
The PMD team is pleased to announce PMD 6.22.0.
This is a minor release.
Table Of Contents
New and noteworthy
Java 14 Support
This release of PMD brings support for Java 14. PMD can parse Switch Expressions,
which have been promoted to be a standard language feature of Java.
PMD also parses Text Blocks as String literals, which is still a preview
language feature in Java 14.
The new Pattern Matching for instanceof can be used as well as
Records.
Note: The Text Blocks, Pattern Matching for instanceof and Records are all preview language features of OpenJDK 14
and are not enabled by default. In order to
analyze a project with PMD that uses these language features, you'll need to enable it via the environment
variable PMD_JAVA_OPTS
and select the new language version 14-preview
:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 14-preview ...
Note: Support for the extended break statement introduced in Java 12 as a preview language feature
has been removed from PMD with this version. The version "12-preview" is no longer available.
Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
For the changes, see PMD Designer Changelog.
Apex Suppressions
In addition to suppressing violation with the @SuppressWarnings
annotation, Apex now also supports
the suppressions with a NOPMD
comment. See Suppressing warnings.
Improved CPD support for C#
The C# tokenizer is now based on an antlr grammar instead of a manual written tokenizer. This
should give more accurate results and especially fixes the problems with the using statement syntax
(see #2139).
XPath Rules
See the new documentation about Writing XPath Rules.
Note: As of PMD version 6.22.0, XPath versions 1.0 and the 1.0 compatibility mode are deprecated.
XPath 2.0 is superior in many ways, for example for its support for type checking, sequence values,
or quantified expressions. For a detailed but approachable review of the features of XPath 2.0 and above,
see the Saxon documentation.
New Rules
-
The Rule
CognitiveComplexity
(apex-design
) finds methods and classes
that are highly complex and therefore difficult to read and more costly to maintain. In contrast
to cyclomatic complexity, this rule uses "Cognitive Complexity", which is a measure of how
difficult it is for humans to read and understand a method. -
The Rule
TestMethodsMustBeInTestClasses
(apex-errorprone
) finds test methods
that are not residing in a test class. The test methods should be moved to a proper test class.
Support for tests inside functional classes was removed in Spring-13 (API Version 27.0), making classes
that violate this rule fail compile-time. This rule is however useful when dealing with legacy code.
Fixed Issues
- apex
- apex-design
- #2162: [apex] Cognitive Complexity rule
- apex-errorprone
- #639: [apex] Test methods should not be in classes other than test classes
- cs
- #2139: [cs] CPD doesn't understand alternate using statement syntax with C# 8.0
- doc
- #2274: [doc] Java API documentation for PMD
- java
- java-bestpractices
- #2277: [java] FP in UnusedImports for ambiguous static on-demand imports
- java-design
- #911: [java] UselessOverridingMethod false positive when elevating access modifier
- java-errorprone
- java-performance
- #2275: [java] AppendCharacterWithChar flags literals in an expression
- plsql
- #2325: [plsql] NullPointerException while running parsing test for CREATE TRIGGER
- #2327: [plsql] Parsing of WHERE CURRENT OF
- #2328: [plsql] Support XMLROOT
- #2331: [plsql] Fix in Comment statement
- #2332: [plsql] Fixed Execute Immediate statement parsing
- #2340: [plsql] Fixed parsing / as divide or execute
API Changes
Deprecated APIs
Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the @InternalApi
annotation. You'll also get a deprecation warning.
-
Implementations of
RuleViolationFactory
in each
language module, egJavaRuleViolationFactory
.
See javadoc ofRuleViolationFactory
. -
Implementations of
RuleViolation
in each language module,
egJavaRuleViolation
. See javadoc of
RuleViolation
. -
Constructors of
RuleSetFactory
, use factory methods fromRulesetsFactoryUtils
instead -
AbstractApexNodeBase
, and the relatedvisit
methods onApexParserVisitor
and its implementations.
Use <a href="https://javadoc.io/page/net.sourceforge.pmd/pmd-apex/6.22.0/net/sou...
6.21.0 (with designer)
This release is identical to the 6.21.0 release, but it includes the newest version of the rule designer. Technically it's a prerelease of 6.22.0 (you'll find that the jar versions reflect this).
PMD release notes
Please refer to the 6.21.0 PMD release
Designer release notes
Please refer to the 6.21.0 designer release
PMD 6.21.0 (24-January-2020)
24-January-2020 - 6.21.0
The PMD team is pleased to announce PMD 6.21.0.
This is a minor release.
Table Of Contents
New and noteworthy
Modelica support
Thanks to Anatoly Trosinenko PMD supports now a new language:
Modelica is a language to model complex physical systems.
Both PMD and CPD are supported and there are already 3 rules available.
The PMD Designer supports syntax highlighting for Modelica.
While the language implementation is quite complete, Modelica support is considered experimental
for now. This is to allow us to change the rule API (e.g. the AST classes) slightly and improve
the implementation based on your feedback.
Simple XML dump of AST
We added a experimental feature to dump the AST of a source file into XML. The XML format
is of course PMD specific and language dependent. That XML file can be used to execute
(XPath) queries against without PMD. It can also be used as a textual visualization of the AST
if you don't want to use the Designer.
This feature is experimental and might change or even be removed in the future, if it is not
useful. A short description how to use it is available under Creating XML dump of the AST.
Any feedback about it, especially about your use cases, is highly appreciated.
Updated Apex Support
- The Apex language support has been bumped to version 48 (Spring '20). All new language features are now properly
parsed and processed.
CPD XML format
The CPD XML output format has been enhanced to also report column information for found duplications
in addition to the line information. This allows to display the exact tokens, that are considered
duplicate.
If a CPD language doesn't provide these exact information, then these additional attributes are omitted.
Each <file>
element in the XML format now has 3 new attributes:
- attribute
endline
- attribute
column
(if there is column information available) - attribute
endcolumn
(if there is column information available)
Modified Rules
-
The Java rule
AvoidLiteralsInIfCondition
(java-errorprone
) has a new property
ignoreExpressions
. This property is set by default totrue
in order to maintain compatibility. If this
property is set to false, then literals in more complex expressions are considered as well. -
The Apex rule
ApexCSRF
(apex-errorprone
) has been moved from category
"Security" to "Error Prone". The Apex runtime already prevents DML statements from being executed, but only
at runtime. So, if you try to do this, you'll get an error at runtime, hence this is error prone. See also
the discussion on #2064. -
The Java rule
CommentRequired
(java-documentation
) has a new property
classCommentRequirement
. This replaces the now deprecated propertyheaderCommentRequirement
, since
the name was misleading. (File) header comments are not checked, but class comments are.
Fixed Issues
- apex
- #2208: [apex] ASTFormalComment should implement ApexNode<T>
- core
- #1984: [java] Cyclomatic complexity is misreported (lack of clearing metrics cache)
- #2006: [core] PMD should warn about multiple instances of the same rule in a ruleset
- #2161: [core] ResourceLoader is deprecated and marked as internal but is exposed
- #2170: [core] DocumentFile doesn't preserve newlines
- doc
- #2214: [doc] Link broken in pmd documentation for writing Xpath rules
- java
- #2212: [java] JavaRuleViolation reports wrong class name
- java-bestpractices
- #2149: [java] JUnitAssertionsShouldIncludeMessage - False positive with assertEquals and JUnit5
- java-codestyle
- #2167: [java] UnnecessaryLocalBeforeReturn false positive with variable captured by method reference
- java-documentation
- #1683: [java] CommentRequired property names are inconsistent
- java-errorprone
- java-performance
- #2141: [java] StringInstatiation: False negative with String-array access
- plsql
API Changes
Deprecated APIs
Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the @InternalApi
annotation. You'll also get a deprecation warning.
-
Implementations of
RuleViolationFactory
in each
language module, egJavaRuleViolationFactory
.
See javadoc ofRuleViolationFactory
. -
Implementations of
RuleViolation
in each language module,
egJavaRuleViolation
. See javadoc of
RuleViolation
. -
Constructors of
RuleSetFactory
, use factory methods fromRulesetsFactoryUtils
instead -
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 clas...
PMD 6.20.0 (29-November-2019)
29-November-2019 - 6.20.0
The PMD team is pleased to announce PMD 6.20.0.
This is a minor release.
Table Of Contents
Fixed Issues
- apex
- core
- #2002: [doc] Issue with http://pmdapplied.com/ linking to a gambling Web site
- #2062: [core] Shortnames parameter does not work with Ant
- #2090: [ci] Release notes and draft releases
- #2096: [core] Referencing category errorprone.xml produces deprecation warnings for InvalidSlf4jMessageFormat
- java
- java-bestpractices
- #2016: [java] UnusedImports: False positive if wildcard is used and only static methods
- java-codestyle
- java-design
- java-errorprone
- #2102: [java] False positive MissingStaticMethodInNonInstantiatableClass when inheritors are instantiable
External Contributions
- #2088: [java] Add more version shortcuts for older java - Henning Schmiedehausen
- #2089: [core] Minor unrelated improvements to code - Gonzalo Exequiel Ibars Ingman
- #2091: [core] Fix pmd warnings (IdenticalCatchCases) - Gonzalo Exequiel Ibars Ingman
- #2106: [java] Wrong name for inner classes - Andi Pabst
- #2121: [java] Predicates treated like booleans - Ozan Gulle
PMD 6.19.0 (31-October-2019)
31-October-2019 - 6.19.0
The PMD team is pleased to announce PMD 6.19.0.
This is a minor release.
Table Of Contents
New and noteworthy
Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
For the changes, see PMD Designer Changelog.
Java Metrics
- The new metric "Class Fan Out Complexity" has been added. See
Java Metrics Documentation for details.
Modified Rules
-
The Java rules
InvalidLogMessageFormat
andMoreThanOneLogger
(java-errorprone
) now both support Log4j2. Note that the
rule "InvalidSlf4jMessageFormat" has been renamed to "InvalidLogMessageFormat" to reflect the fact, that it now
supports more than slf4j. -
The Java rule
LawOfDemeter
(java-design
) ignores now also Builders, that are
not assigned to a local variable, but just directly used within a method call chain. The method, that creates
the builder needs to end with "Builder", e.g.newBuilder()
orinitBuilder()
works. This change
fixes a couple of false positives. -
The Java rule
DataflowAnomalyAnalysis
(java-errorprone
) doesn't check for
UR anomalies (undefined and then referenced) anymore. These checks were all false-positives, since actual
UR occurrences would lead to compile errors. -
The java rule
DoNotUseThreads
(java-multithreading
) has been changed
to not report usages ofjava.lang.Runnable
anymore. Just usingRunnable
does not automatically create
a new thread. While the check forRunnable
has been removed, the rule now additionally checks for
usages ofExecutors
andExecutorService
. Both create new threads, which are not managed by a J2EE
server.
Renamed Rules
- The Java rule
InvalidSlf4jMessageFormat
has been renamed to
InvalidLogMessageFormat
since it supports now both slf4j and log4j2
message formats.
Fixed Issues
- core
- #1978: [core] PMD fails on excluding unknown rules
- #2014: [core] Making add(SourceCode sourceCode) public for alternative file systems
- #2020: [core] Wrong deprecation warnings for unused XPath attributes
- #2036: [core] Wrong include/exclude patterns are silently ignored
- #2048: [core] Enable type resolution by default for XPath rules
- #2067: [core] Build issue on Windows
- #2068: [core] Rule loader should use the same resources loader for the ruleset
- #2071: [ci] Add travis build on windows
- #2072: [test][core] Not enough info in "test setup error" when numbers of lines do not match
- #2082: [core] Incorrect logging of deprecated/renamed rules
- java
- #2042: [java] PMD crashes with ClassFormatError: Absent Code attribute...
- java-bestpractices
- java-codestyle
- #2017: [java] UnnecessaryFullyQualifiedName triggered for inner class
- java-design
- #1912: [java] Metrics not computed correctly with annotations
- java-errorprone
- java-multithreading
- #1627: [java] DoNotUseThreads should not warn on Runnable
- doc
- #2058: [doc] CLI reference for
-norulesetcompatibility
shows a boolean default value
- #2058: [doc] CLI reference for
API Changes
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 implementations- [
isSupressed
](https://javadoc.io/page/net.sourceforge.pmd/pmd-apex/6.19.0/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolation.html#isSupressed(Node,R...
PMD 6.18.0 (15-September-2019)
15-September-2019 - 6.18.0
The PMD team is pleased to announce PMD 6.18.0.
This is a minor release.
Table Of Contents
New and noteworthy
Java 13 Support
This release of PMD brings support for Java 13. PMD can parse Switch Expressions
with the new yield
statement and resolve the type of such an expression.
PMD also parses Text Blocks as String literals.
Note: The Switch Expressions and Text Blocks are a preview language feature of OpenJDK 13
and are not enabled by default. In order to
analyze a project with PMD that uses these language features, you'll need to enable it via the environment
variable PMD_JAVA_OPTS
and select the new language version 13-preview
:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 13-preview ...
Note: Support for the extended break statement introduced in Java 12 as a preview language feature
will be removed with the next PMD version 6.19.0.
Full support for Scala
Thanks to Chris Smith PMD now fully supports Scala. Now rules for analyzing Scala
code can be developed in addition to the Copy-Paste-Detection (CPD) functionality. There are no rules yet, so
contributions are welcome.
Additionally Scala support has been upgraded from 2.12.4 to 2.13.
New rule designer documentation
The documentation for the rule designer is now available on the main PMD documentation page:
Rule Designer Reference. Check it out to learn
about the usage and features of the rule designer.
New rules
-
The Java rule
AvoidMessageDigestField
(java-bestpractices
) detects fields
of the typejava.security.MessageDigest
. Using a message digest instance as a field would need to be
synchronized, as it can easily be used by multiple threads. Without synchronization the calculated hash could
be entirely wrong. Instead of declaring this as a field and synchronize access to use it from multiple threads,
a new instance should be created when needed. This rule is also active when using java's quickstart ruleset. -
The Apex rule
DebugsShouldUseLoggingLevel
(apex-bestpractices
) detects
usages ofSystem.debug()
method calls that are used without specifying the log level. Having the log
level specified provides a cleaner log, and improves readability of it.
Modified Rules
- The Java rule
CloseResource
(java-errorprone
) now ignores by default instances
ofjava.util.stream.Stream
. These streams areAutoCloseable
, but most streams are backed by collections,
arrays, or generating functions, which require no special resource management. However, there are some exceptions:
The stream returned byFiles::lines(Path)
is backed by a actual file and needs to be closed. These instances
won't be found by default by the rule anymore.
Fixed Issues
- all
- #1465: [core] Stylesheet pmd-report.xslt fails to display filepath if 'java' in path
- #1923: [core] Incremental analysis does not work with shortnames
- #1983: [core] Avoid crashes with analysis cache when classpath references non-existing directories
- #1990: [core] Incremental analysis mixes XPath rule violations
- apex
- java
- #1930: [java] Add Java 13 support
- java-bestpractices
- java-codestyle
- #1951: [java] UnnecessaryFullyQualifiedName rule triggered when variable name clashes with package name
- java-errorprone
- plsql
- #1933: [plsql] ParseException with cursor declared in anonymous block
- #1935: [plsql] ParseException with SELECT INTO record defined as global variable
- #1936: [plslq] ParseException with cursor inside procedure declaration
- #1946: [plsql] ParseException with using TRIM inside IF statements condition
- #1947: [plsql] ParseError - SELECT with FOR UPDATE OF
- #1948: [plsql] ParseException with INSERT INTO using package global variables
- #1950: [plsql] ParseException with UPDATE and package record variable
- #1953: [plsql] ParseException with WITH in CURSOR
API Changes
Changes to Renderer
-
Each renderer has now a new method
Renderer#setUseShortNames
which
is used for implementing the "shortnames" CLI option. The method is automatically called by PMD, if this
CLI option is in use. When rendering filenames to the report, the new helper method
AbstractRenderer#determineFileName
should be used. This will change
the filename to a short name, if the CLI option "shortnames" is used.Not adjusting custom renderers will make them render always the full file names and not honoring the
CLI option "shortnames".
Deprecated APIs
For removal
- The methods
getImportedNameNode
and
getPackage
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 targeting
StatisticalRule
.
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.p...