29 May 2018
The PMD team is pleased to announce PMD 6.4.0.
This is a minor release.
PMD is now able to understand local-variable type inference as introduced by Java 10.
Simple type resolution features are available, e.g. the type of the variable s is inferred
correctly as String:
var s = "Java 10";
For some time now PMD has supported Type Resolution, and exposed this functionality to XPath rules for the Java language
with the typeof function. This function however had a number of shortcomings:
@Image
but was still required.In this release we are deprecating typeof in favor of a simpler typeIs function, which behaves exactly as the
old typeof when given all 3 arguments.
typeIs receives a single parameter, which is the fully qualified name of the class to test against.
So, calls such as:
//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase', 'TestCase')]
can now we expressed much more concisely as:
//ClassOrInterfaceType[typeIs('junit.framework.TestCase')]
With this change, we also allow to check against array types by just appending [] to the fully qualified class name.
These can be repeated for arrays of arrays (e.g. byte[][] or java.lang.String[]).
Additionally, we introduce the companion function typeIsExactly, that receives the same parameters as typeIs,
but checks for exact type matches, without considering the type hierarchy. That is, the test
typeIsExactly('junit.framework.TestCase') will match only if the context node is an instance of TestCase, but
not if it’s an instance of a subclass of TestCase. Be aware then, that using that method with abstract types will
never match.
The new Java rule HardCodedCryptoKey (java-security)
detects hard coded keys used for encryption. It is recommended to store keys outside of the source code.
The new Java rule IdenticalCatchBranches (java-codestyle)
finds catch blocks,
that catch different exception but perform the same exception handling and thus can be collapsed into a
multi-catch try statement.
The Java rule JUnit4TestShouldUseTestAnnotation (java-bestpractices)
has a new parameter “testClassPattern”. It is used to distinguish test classes from other classes and
avoid false positives. By default, any class, that has “Test” in its name, is considered a test class.
The Java rule CommentDefaultAccessModifier (java-codestyle)
allows now by default the comment “/* package */ in addition to “/* default */. This behavior can
still be adjusted by setting the property regex.
net.sourceforge.pmd.benchmark have been deprecated: Benchmark, Benchmarker,
BenchmarkReport, BenchmarkResult, RuleDuration, StringBuilderCR and TextReport. Their API is not supported anymore
and is disconnected from the internals of PMD. Use the newer API based around TimeTracker instead, which can be found
in the same package.net.sourceforge.pmd.lang.java.xpath.TypeOfFunction has been deprecated. Use the newer TypeIsFunction in the same package.typeof methdos in net.sourceforge.pmd.lang.java.xpath.JavaFunctions have been deprecated.
Use the newer typeIs method in the same class instead..isA, isEither and isNeither of net.sourceforge.pmd.lang.java.typeresolution.TypeHelper.
Use the new isExactlyAny and isExactlyNone methods in the same class instead.DoNotExtendJavaLangError - Akshat Bahety