31 March 2019
The PMD team is pleased to announce PMD 6.13.0.
This is a minor release.
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.
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 ...
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.
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.
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 and Field[@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.ModifierNode
node has a couple of attributes to check for the existence of specific
modifiers: @Test
, @TestOrTestSetup
, @WithSharing
, @WithoutSharing
, @InheritedSharing
,
@WebService
, @Global
, @Override
.Parameter[@Type='Integer']
you can find all
method parameters of type Integer. The same attribute Type
exists as well for:
NewObjectExpression
, Property
, VariableDeclaration
.VariableExpression[@Image='i']
finds all variable usages of the variable “i”.The new Java rule AvoidUncheckedExceptionsInSignatures
(java-design
) finds methods or constructors
that declare unchecked exceptions in their throws
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 simply true
or false
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.
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.
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 ruleset rulesets/apex/quickstart.xml
instead.