Releases: pmd/pmd
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...
PMD 6.17.0 (28-July-2019)
28-July-2019 - 6.17.0
The PMD team is pleased to announce PMD 6.17.0.
This is a minor release.
Table Of Contents
New and noteworthy
Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
For the changes, see PMD Designer Changelog.
It contains a new feature to edit test cases directly within the designer. Any feedback is highly appreciated.
Lua support
Thanks to the contribution from Maikel Steneker, and built on top of the ongoing efforts to fully support Antlr-based languages,
PMD now has CPD support for Lua.
Being based on a proper Antlr grammar, CPD can:
- ignore comments
- honor comment-based suppressions
Modified Rules
-
The Java rule
CloseResource
(java-errorprone
) ignores now by default
java.io.ByteArrayInputStream
andjava.io.CharArrayWriter
. Such streams/writers do not need to be closed. -
The Java rule
MissingStaticMethodInNonInstantiatableClass
(java-errorprone
) has now
the new propertyannotations
.
When one of the private constructors is annotated with one of the annotations, then the class is not considered
non-instantiatable anymore and no violation will be reported. By default, Spring's@Autowired
and
Java EE's@Inject
annotations are recognized.
Fixed Issues
- core
- #1913: [core] "-help" CLI option ends with status code != 0
- doc
- #1896: [doc] Error in changelog 6.16.0 due to not properly closed rule tag
- #1898: [doc] Incorrect code example for DoubleBraceInitialization in documentation on website
- #1906: [doc] Broken link for adding own CPD languages
- #1909: [doc] Sample usage example refers to deprecated ruleset "basic.xml" instead of "quickstart.xml"
- java
- #1910: [java] ATFD calculation problem
- java-errorprone
- java-multithreading
- #1903: [java] UnsynchronizedStaticFormatter doesn't allow block-level synchronization when using allowMethodLevelSynchronization=true
- plsql
- #1902: [pslql] ParseException when parsing (+)
- xml
- #1666: [xml] wrong cdata rule description and examples
External Contributions
- #1869: [xml] fix #1666 wrong cdata rule description and examples - Artem
- #1892: [lua] [cpd] Added CPD support for Lua - Maikel Steneker
- #1905: [java] DataflowAnomalyAnalysis Rule in right order - YoonhoChoi96
- #1908: [doc] Update ruleset filename from deprecated basic.xml to quickstart.xml - crunsk
- #1916: [java] Exclude Autowired and Inject for MissingStaticMethodInNonInstantiatableClass - AnthonyKot
- #1917: [core] Add 'no error' return option, and assign it to the cli when the help command is invoked - Renato Oliveira
PMD 6.16.0 (30-June-2019)
30-June-2019 - 6.16.0
The PMD team is pleased to announce PMD 6.16.0.
This is a minor release.
Table Of Contents
New and noteworthy
Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
For the changes, see PMD Designer Changelog.
PLSQL Grammar Updates
The grammar has been updated to support inline constraints in CREATE TABLE statements. Additionally, the
CREATE TABLE statement may now be followed by physical properties and table properties. However, these
properties are skipped over during parsing.
The CREATE VIEW statement now supports subquery views.
The EXTRACT function can now be parsed correctly. It is used to extract values from a specified
datetime field. Also date time literals are parsed now correctly.
The CASE expression can now be properly used within SELECT statements.
Table aliases are now supported when specifying columns in INSERT INTO clauses.
New Rules
-
The Java rule
DoubleBraceInitialization
(java-bestpractices
)
detects non static initializers in anonymous classes also known as "double brace initialization".
This can be problematic, since a new class file is generated and object holds a strong reference
to the surrounding class.Note: This rule is also part of the Java quickstart ruleset (
rulesets/java/quickstart.xml
).
Modified Rules
-
The Java rule
UnusedPrivateField
(java-bestpractices
) now ignores by
default fields, that are annotated with the Lombok experimental annotation@Delegate
. This can be
customized with the propertyignoredAnnotations
. -
The Java rule
SingularField
(java-design
) now ignores by
default fields, that are annotated with the Lombok experimental annotation@Delegate
. This can be
customized with the propertyignoredAnnotations
. -
The Java rules
UnsynchronizedStaticFormatter
and
UnsynchronizedStaticDateFormatter
(java-multithreading
)
now prefer synchronized blocks by default. They will raise a violation, if the synchronization is implemented
on the method level. To allow the old behavior, the new propertyallowMethodLevelSynchronization
can
be enabled. -
The Java rule
UseUtilityClass
(java-design
) has a new propertyignoredAnnotations
.
By default, classes that are annotated with Lombok's@UtilityClass
are ignored now. -
The Java rule
NonStaticInitializer
(java-errorprone
) does not report
non static initializers in anonymous classes anymore. For this use case, there is a new rule now:
DoubleBraceInitialization
(java-bestpractices
). -
The Java rule
CommentDefaultAccessModifier
(java-codestyle
) was enhanced
in the last version 6.15.0 to check also top-level types by default. This created many new violations.
Missing the access modifier for top-level types is not so critical, since it only decreases the visibility
of the type.The default behaviour has been restored. If you want to enable the check for top-level types, you can
use the new propertycheckTopLevelTypes
. -
The Java rule
CloseResource
(java-errorprone
) now by default searches
for any unclosedjava.lang.AutoCloseable
resource. This includes now the standardjava.io.*Stream
classes.
Previously only SQL-related resources were considered by this rule. The types can still be configured
via thetypes
property. Some resources do not need to be closed (e.g.ByteArrayOutputStream
). These
exceptions can be configured via the new propertyallowedResourceTypes
.
In order to restore the old behaviour, just remove the typejava.lang.AutoCloseable
from thetypes
property and keep the remaining SQL-related classes.
Deprecated Rules
- The Java rule
AvoidFinalLocalVariable
(java-codestyle
) has been deprecated
and will be removed with PMD 7.0.0. The rule is controversial and also contradicts other existing
rules such asLocalVariableCouldBeFinal
. If the goal is to avoid defining
constants in a scope smaller than the class, then the ruleAvoidDuplicateLiterals
should be used instead.
Fixed Issues
- apex
- #1664: [apex] False positive ApexSharingViolationsRule, unsupported Apex feature
- java
- #1848: [java] Local classes should preserve their modifiers
- java-bestpractices
- java-codestyle
- java-design
- #1094: [java] UseUtilityClass should be LombokAware
- java-errorprone
- java-multithreading
- plsql
API Changes
Deprecated APIs
Reminder: Please don't use members marked with the annotation
InternalApi
, as they will likely be removed, hidden, or otherwise intentionally broken with 7.0.0.
In ASTs
As part of the changes we'd like to do to AST classes for 7.0.0, we would like to
hide some methods and constructors that rule writers should not have access to.
The following usages are now deprecated in the Java AST (with other languages to come):
- Manual instantiation of nodes. Constructors of node classes are deprecated and marked
InternalApi
. Nodes should only be obtained from the parser, which for rules, means that never need to instantiate node themselves. Those constructors will be made package private with 7.0.0. - Subclassing of abstract node classes, or usage of their type. Version 7.0.0 will bring a new set of abstractions that will be public API, but the base classes are and will stay internal. You should not couple your code to them.
- 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
](https://javadoc.io/page/net.sourceforge....
PMD 6.15.0 (26-May-2019)
26-May-2019 - 6.15.0
The PMD team is pleased to announce PMD 6.15.0.
This is a minor release.
Table Of Contents
New and noteworthy
Enhanced Matlab support
Thanks to the contributions from Maikel Steneker CPD for Matlab can
now parse Matlab programs which use the question mark operator to specify access to
class members:
classdef Class1
properties (SetAccess = ?Class2)
CPD also understands now double quoted strings, which are supported since version R2017a of Matlab:
str = "This is a string"
Enhanced C++ support
CPD now supports digit separators in C++ (language module "cpp"). This is a C++14 feature.
Example: auto integer_literal = 1'000'000;
The single quotes can be used to add some structure to large numbers.
CPD also parses raw string literals now correctly (see #1784).
New Rules
-
The new Apex rule
FieldNamingConventions
(apex-codestyle
) checks the naming
conventions for field declarations. By default this rule uses the standard Apex naming convention (Camel case),
but it can be configured through properties. -
The new Apex rule
FormalParameterNamingConventions
(apex-codestyle
) checks the
naming conventions for formal parameters of methods. By default this rule uses the standard Apex naming
convention (Camel case), but it can be configured through properties. -
The new Apex rule
LocalVariableNamingConventions
(apex-codestyle
) checks the
naming conventions for local variable declarations. By default this rule uses the standard Apex naming
convention (Camel case), but it can be configured through properties. -
The new Apex rule
PropertyNamingConventions
(apex-codestyle
) checks the naming
conventions for property declarations. By default this rule uses the standard Apex naming convention (Camel case),
but it can be configured through properties. -
The new Java rule
UseShortArrayInitializer
(java-codestyle
) searches for
array initialization expressions, which can be written shorter.
Modified Rules
-
The Apex rule
ClassNamingConventions
(apex-codestyle
) can now be configured
using various properties for the specific kind of type declarations (e.g. class, interface, enum).
As before, this rule uses by default the standard Apex naming convention (Pascal case). -
The Apex rule
MethodNamingConventions
(apex-codestyle
) can now be configured
using various properties to differenciate e.g. static methods and test methods.
As before, this rule uses by default the standard Apex naming convention (Camel case). -
The Java rule
FieldNamingConventions
(java-codestyle
) now by default ignores
the fieldserialPersistentFields
. Since this is a field which needs to have this special name, no
field naming conventions can be applied here. It is excluded the same way likeserialVersionUID
via the
propertyexclusions
. -
The Java rule
CommentRequired
(java-documentation
) has a new property
serialPersistentFieldsCommentRequired
with the default value "Ignored". This means that from now
on comments for the fieldserialPersistentFields
are not required anymore. You can change the property
to restore the old behavior. -
The Java rule
ProperLogger
(java-errorprone
) has two new properties
to configure the logger class (e.g. "org.slf4j.Logger") and the logger name of the special case,
when the logger is not static. The name of the static logger variable was already configurable.
The new property "loggerClass" allows to use this rule for different logging frameworks.
This rule covers all the cases of the now deprecated ruleLoggerIsNotStaticFinal
. -
The Java rule
CommentDefaultAccessModifier
(java-codestyle
) now reports also
missing comments for top-level classes and annotations, that are package-private.
Deprecated Rules
-
The Apex rule
VariableNamingConventions
(apex-codestyle
) has been deprecated and
will be removed with PMD 7.0.0. The rule is replaced by the more general rules
FieldNamingConventions
,
FormalParameterNamingConventions
,
LocalVariableNamingConventions
, and
PropertyNamingConventions
. -
The Java rule
LoggerIsNotStaticFinal
(java-errorprone
) has been deprecated
and will be removed with PMD 7.0.0. The rule is replaced byProperLogger
.
Fixed Issues
- apex
- cpp
- #1784: [cpp] Improve support for raw string literals
- dart
- #1809: [dart] [cpd] Parse error with escape sequences
- java
- #1842: [java] Annotated module declarations cause parse error
- java-bestpractices
- #1738: [java] MethodReturnsInternalArray does not work in inner classes
- java-codestyle
- python
- #1810: [python] [cpd] Parse error when using Python 2 backticks
- matlab
API Changes
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 metho...
PMD 6.14.0 (28-April-2019)
28-April-2019 - 6.14.0
The PMD team is pleased to announce PMD 6.14.0.
This is a minor release.
Table Of Contents
New and noteworthy
Dart support
Thanks to the contribution from Maikel Steneker, and built on top of the ongoing efforts to fully support Antlr-based languages,
PMD now has CPD support for Dart.
Being based on a proper Antlr grammar, CPD can:
- ignore comments
- ignore imports / libraries
- honor comment-based suppressions
Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
For the changes, see PMD Designer Changelog.
Modified Rules
-
The Java rule
AssignmentToNonFinalStatic
(java-errorprone
) will now report on each
assignment made within a constructor rather than on the field declaration. This makes it easier for developers to
find the offending statements. -
The Java rule
NoPackage
(java-codestyle
) will now report additionally enums
and annotations that do not have a package declaration.
Fixed Issues
- all
- go
- #1751: [go] Parsing errors encountered with escaped backslash
- java
- java-bestpractices
- java-codestyle
- java-design
- #1760: [java] UseObjectForClearerAPI flags private methods
API Changes
No changes.
External Contributions
- #1745: [doc] Fixed some errors in docs - 0xflotus
- #1746: [java] Update rule to prevent UnusedImport when using JavaDoc with array type - itaigilo
- #1752: [java] UseObjectForClearerAPI Only For Public - Björn Kautler
- #1761: [dart] [cpd] Added CPD support for Dart - Maikel Steneker
- #1776: [java] Show more detailed message when can't resolve field type - Andrey Fomin
- #1781: [java] Location change in AssignmentToNonFinalStatic - Maikel Steneker
- #1789: [cpd] [core] Use current classloader instead of Thread's classloader - Andreas Schmid
- #1791: [dart] [cpd] Dart escaped string - Maikel Steneker
PMD 6.13.0 (31-March-2019)
31-March-2019 - 6.13.0
The PMD team is pleased to announce PMD 6.13.0.
This is a minor release.
Table Of Contents
New and noteworthy
Call For Logo
We are still searching for a new logo for PMD for the next major release.
Learn more about how to participate on github issue 1663.
Java 12 Support
This release of PMD brings support for Java 12. PMD can parse the new Switch Expressions
and resolve the type of such an expression.
Note: The Switch Expressions are a preview language feature of OpenJDK 12 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 new environment
variable PMD_JAVA_OPTS
:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd ...
Quickstart Ruleset for Apex
PMD provides now a quickstart ruleset for Salesforce.com Apex, which you can use as a base ruleset to
get your custom ruleset started. You can reference it with rulesets/apex/quickstart.xml
.
You are strongly encouraged to create your own ruleset
though.
The quickstart ruleset has the intention, to be useful out-of-the-box for many projects. Therefore it
references only rules, that are most likely to apply everywhere.
Any feedback would be greatly appreciated.
PMD Designer
The rule designer's codebase has been moved out of the main repository and
will be developed at pmd/pmd-designer
from now on. The maven coordinates will stay the same for the time being.
The designer will still be shipped with PMD's binaries.
Improved Apex Support
- Many AST nodes now expose more information which makes it easier to write XPath-based rules for Apex. Here are
some examples:Annotation[@Resolved = false()]
finds unsupported annotations.AnnotationParameter[@Name='RestResource'][@Value='/myurl']
gives access to
annotation parameters.CatchBlockStatement[@ExceptionType='Exception'][@VariableName='e']
finds catch
block for specific exception types.Field[@Type='String']
find all String fields,Field[string-length(@Name) < 5]
finds all fields with short names andField[@Value='a']
find alls fields, that are
initialized with a specific value.LiteralExpression[@String = true()]
finds all String literals. There are attributes
for each type:@Boolean
,@Integer
,@Double
,@Long
,@Decimal
,@Null
.Method[@Constructor = true()]
selects all constructors.Method[@ReturnType = 'String']
selects all methods that return a String.- The
ModifierNode
node has a couple of attributes to check for the existence of specific
modifiers:@Test
,@TestOrTestSetup
,@WithSharing
,@WithoutSharing
,@InheritedSharing
,
@WebService
,@Global
,@Override
. - Many nodes now expose their type. E.g. with
Parameter[@Type='Integer']
you can find all
method parameters of type Integer. The same attributeType
exists as well for:
NewObjectExpression
,Property
,VariableDeclaration
. VariableExpression[@Image='i']
finds all variable usages of the variable "i".
New Rules
-
The new Java rule
AvoidUncheckedExceptionsInSignatures
(java-design
) finds methods or constructors
that declare unchecked exceptions in theirthrows
clause. This forces the caller to handle the exception,
even though it is a runtime exception. -
The new Java rule
DetachedTestCase
(java-errorprone
) searches for public
methods in test classes, which are not annotated with@Test
. These methods might be test cases where
the annotation has been forgotten. Because of that those test cases are never executed. -
The new Java rule
WhileLoopWithLiteralBoolean
(java-bestpractices
) finds
Do-While-Loops and While-Loops that can be simplified since they use simplytrue
orfalse
as their
loop condition. -
The new Apex rule
ApexAssertionsShouldIncludeMessage
(apex-bestpractices
)
searches for assertions in unit tests and checks, whether they use a message argument. -
The new Apex rule
ApexUnitTestMethodShouldHaveIsTestAnnotation
(apex-bestpractices
)
searches for methods in test classes, which are missing the@IsTest
annotation. -
The new PLSQL rule
AvoidTabCharacter
(plsql-codestyle
) checks, that there are
no tab characters ("\t") in the source file. -
The new PLSQL rule
LineLength
(plsql-codestyle
) helps to enforce a maximum
line length.
Fixed Issues
- doc
- #1721: [doc] Documentation provides an invalid property configuration example
- java
- #1537: [java] Java 12 support
- java-bestpractices
- #1701: [java] UseTryWithResources does not handle multiple argument close methods
- java-codestyle
- java-errorprone
- #1570: [java] AvoidDuplicateLiterals warning about deprecated separator property when not used
- plsql
- #1510: [plsql] Support XMLTABLE functions
- #1716: [plsql] Support access to whole plsql code
- #1731: [pslql] ParseException when parsing ELSIF
- #1733: [plsql] % not supported in "TestSearch%notfound"
- #1734: [plsql] TooManyMethods false-negative
- #1735: [plsql] False-negatives for TO_DATE_TO_CHAR, TO_DATEWithoutDateFormat, TO_TIMESTAMPWithoutDateFormat
API Changes
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.
External Contributions
- #1694: [apex] New rules for test method and assert statements - triandicAnt
- #1697: [doc] Update CPD documentation - Matías Fraga
- #1704: [java] Added AvoidUncheckedExceptionsInSignatures Rule - Bhanu Prakash Pamidi
- #1706: [java] Add DetachedTestCase rule - David Burström
- #1709: [java] Detect while loops with literal booleans conditions - David Burström
- #1717: [java] Fix false positive in useTryWithResources when using a custom close method with multiple arguments - Rishabh Jain
- #1724: [doc] Correct property override example - Felix W. Dekker
- #1737: [java] fix escaping of CommentDefaultAccessModifier documentation - itaigilo