We’re excited to bring you the next major version of PMD! Here are the major features and changes we’re working on. To give us feedback or to suggest a new feature, drop us a line on Gitter!
New Features
TODO
Java grammar changes
New API support guidelines
What’s new
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.
The transition
All currently supported APIs will remain so until 7.0.0. All APIs that are to be moved to
.internal packages or hidden will be tagged @InternalApi before that major release, and
the breaking API changes will be performed in 7.0.0.
Planned API removals
List of currently deprecated APIs
@Deprecated or not in the latest minor release. During the development of 7.0.0,
we may decide to remove some APIs that were not tagged as deprecated, though we’ll try to avoid it.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
DumpFacadesin 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.DumpFacadenet.sourceforge.pmd.lang.java.ast.DumpFacadenet.sourceforge.pmd.lang.ecmascript.ast.DumpFacadenet.sourceforge.pmd.lang.jsp.ast.DumpFacadenet.sourceforge.pmd.lang.plsql.ast.DumpFacadenet.sourceforge.pmd.lang.vf.ast.DumpFacadenet.sourceforge.pmd.lang.vm.ast.AbstractVmNode#dumpnet.sourceforge.pmd.lang.xml.ast.DumpFacade
- The method
LanguageVersionHandler#getDumpFacadewill 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
-
CodeClimateRuleis 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.xmlhas been deprecated and will be removed in 7.0.0. Please use the new quickstart rulesetrulesets/apex/quickstart.xmlinstead.
6.12.0
No changes.
6.11.0
StatisticalRuleand the related helper classes and base rule classes are deprecated for removal in 7.0.0. This includes all ofnet.sourceforge.pmd.statandnet.sourceforge.pmd.lang.rule.stat, and alsoAbstractStatisticalJavaRule,AbstractStatisticalApexRuleand the like. The methodsReport#addMetricandmetricAddedwill also be removed.setPropertyis deprecated, becauseMultiValuePropertyDescriptoris 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
IntegerPropertyandStringMultiPropertywill gradually all be deprecated until 7.0.0. Their usages should be replaced by direct usage of thePropertyDescriptorinterface, e.g.PropertyDescriptor<Integer>orPropertyDescriptor<List<String>>. -
Instead of spreading properties across countless classes, the utility class
PropertyFactorywill 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:IntegerPropertyis replaced byPropertyFactory#intPropertyIntegerMultiPropertyis replaced byPropertyFactory#intListProperty
FloatPropertyandDoublePropertyare both replaced byPropertyFactory#doubleProperty. Having a separate property for floats wasn’t that useful.- Similarly,
FloatMultiPropertyandDoubleMultiPropertyare replaced byPropertyFactory#doubleListProperty.
- Similarly,
StringPropertyis replaced byPropertyFactory#stringPropertyStringMultiPropertyis replaced byPropertyFactory#stringListProperty
-
RegexPropertyis replaced byPropertyFactory#regexProperty EnumeratedPropertyis replaced byPropertyFactory#enumPropertyEnumeratedPropertyis replaced byPropertyFactory#enumListProperty
BooleanPropertyis replaced byPropertyFactory#booleanProperty- Its multi-valued counterpart,
BooleanMultiProperty, is not replaced, because it doesn’t have a use case.
- Its multi-valued counterpart,
CharacterPropertyis replaced byPropertyFactory#charPropertyCharacterMultiPropertyis replaced byPropertyFactory#charListProperty
LongPropertyis replaced byPropertyFactory#longIntPropertyLongMultiPropertyis replaced byPropertyFactory#longIntListProperty
MethodProperty,FileProperty,TypePropertyand 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 toPropertyConstraints, which will allow virtually any constraint to be defined, and improve documentation and error reporting. The related methodsPropertyTypeId#isPropertyNumericandPropertyTypeId#isPropertyPackagedare also deprecated. -
MultiValuePropertyDescriptorandSingleValuePropertyDescriptorare 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#isMultiValuewill be removed accordingly.
Changes to the PropertyDescriptor interface
preferredRowCountis deprecated with no intended replacement. It was never implemented, and does not belong in this interface. The methodsuiOrderandcompareTo(PropertyDescriptor)are deprecated for the same reason. These methods mix presentation logic with business logic and are not necessary for PropertyDescriptors to work.PropertyDescriptorwill not extendComparable<PropertyDescriptor>anymore come 7.0.0.- The method
propertyErrorForis deprecated and will be removed with no intended replacement. It’s really just a shortcut forprop.errorFor(rule.getProperty(prop)). TvalueFrom(String)andStringasDelimitedString(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.isMultiValueandtypeare 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,typewill 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.errorForis 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. OnlyAttributeremains public API. -
The classes
PropertyDescriptorField,PropertyDescriptorBuilderConversionWrapper, and the methodsPropertyDescriptor#attributeValuesById,PropertyDescriptor#isDefinedExternallyandPropertyTypeId#getFactory. These were used to read and write properties to and from XML, but were not intended as public API. -
The class
ValueParserConstantsand the interfaceValueParser. -
All classes from
net.sourceforge.pmd.lang.java.metrics.impl.visitorsare 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,JavaParserVisitorAdaptershould be directly subclassed. -
LanguageVersionHandler#getDataFlowHandler(),LanguageVersionHandler#getDFAGraphRule()
For removal
-
All classes from
net.sourceforge.pmd.properties.moduleswill be removed. -
The interface
Dimensionablehas 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
ASTLocalVariableDeclarationandASTFieldDeclarationhave also been deprecated:-
ASTFieldDeclarationwon’t be aTypeNodecome 7.0.0, sogetTypeandgetTypeDefinitionare deprecated. -
The method
getVariableNameon 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<ASTVariableDeclaratorId>though, so you should iterate on each declared variable. See #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, andJavaParserVisitorDecoratorare deprecated with no intended replacement.
- In
-
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:
CppHandlerCppLanguageModuleCppParserCsLanguageModuleFortranLanguageModuleGroovyLanguageModuleMatlabHandlerMatlabLanguageModuleMatlabParserObjectiveCHandlerObjectiveCLanguageModuleObjectiveCParserPhpLanguageModulePythonHandlerPythonLanguageModulePythonParserRubyLanguageModuleScalaLanguageModuleSwiftLanguageModule
-
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.AbstractPropertySourcehave 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.PropertySourcehave been deprecated as well:usesDefaultValues(),useDefaultValueFor(),ignoredProperties(). -
The class
net.sourceforge.pmd.lang.rule.AbstractDelegateRulehas 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.RuleReferencehas 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.reporthave 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.CommentUtilhas 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 childrenJavadocElementnodes, 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.benchmarkhave been deprecated:Benchmark,Benchmarker,BenchmarkReport,BenchmarkResult,RuleDuration,StringBuilderCRandTextReport. Their API is not supported anymore and is disconnected from the internals of PMD. Use the newer API based aroundTimeTrackerinstead, which can be found in the same package. - The class
net.sourceforge.pmd.lang.java.xpath.TypeOfFunctionhas been deprecated. Use the newerTypeIsFunctionin the same package. - The
typeofmethods innet.sourceforge.pmd.lang.java.xpath.JavaFunctionshave been deprecated. Use the newertypeIsmethod in the same class instead.. - The methods
isA,isEitherandisNeitherofnet.sourceforge.pmd.lang.java.typeresolution.TypeHelper. Use the newisExactlyAnyandisExactlyNonemethods 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 bothASTConstructorDeclarationandASTMethodDeclaration.
6.1.0
- The method
getXPathNodeNameis added to theNodeinterface, which removes the use of thetoStringof 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.toStringmethod will not necessarily provide its XPath node name anymore.
- The default implementation provided in
-
The interface
net.sourceforge.pmd.cpd.Rendererhas been deprecated. A new interfacenet.sourceforge.pmd.cpd.renderer.CPDRendererhas been introduced to replace it. The main difference is that the new interface is meant to render directly to ajava.io.Writerrather than to a String. This allows to greatly reduce the memory footprint of CPD, as on large projects, with many duplications, it was causingOutOfMemoryErrors (see #795).net.sourceforge.pmd.cpd.FileReporterhas also been deprecated as part of this change, as it’s no longer needed.
6.0.1
- The constant
net.sourceforge.pmd.PMD.VERSIONhas been deprecated and will be removed with PMD 7.0.0. Please usenet.sourceforge.pmd.PMDVersion.VERSIONinstead.
List of currently deprecated rules
-
The Java rules
VariableNamingConventions,MIsLeadingVariableName,SuspiciousConstantFieldName, andAvoidPrefixingMethodParametersare now deprecated, and will be removed with version 7.0.0. They are replaced by the more generalFieldNamingConventions,FormalParameterNamingConventions, andLocalVariableNamingConventions. -
The Java rule
AbstractNamingis deprecated in favour ofClassNamingConventions. -
The Java rules
WhileLoopsMustUseBraces,ForLoopsMustUseBraces,IfStmtsMustUseBraces, andIfElseStmtsMustUseBracesare deprecated. They will be replaced by the new ruleControlStatementBraces. -
The Java rules
NcssConstructorCount,NcssMethodCount, andNcssTypeCounthave been deprecated. They will be replaced by the new ruleNcssCountin the categorydesign. -
The Java rule
LooseCouplingin rulesetjava-typeresolutionis deprecated. Use the rule with the same name from categorybestpracticesinstead. -
The Java rule
CloneMethodMustImplementCloneablein rulesetjava-typeresolutionis deprecated. Use the rule with the same name from categoryerrorproneinstead. -
The Java rule
UnusedImportsin rulesetjava-typeresolutionis deprecated. Use the rule with the same name from categorybestpracticesinstead. -
The Java rule
SignatureDeclareThrowsExceptionin rulesetjava-typeresolutionis deprecated. Use the rule with the same name from categorydesigninstead. -
The Java rule
EmptyStaticInitializerin rulesetjava-emptyis deprecated. Use the ruleEmptyInitializer, which covers both static and non-static empty initializers.` -
The Java rules
GuardDebugLogging(rulesetjava-logging-jakarta-commons) andGuardLogStatementJavaUtil(rulesetjava-logging-java) have been deprecated. Use the ruleGuardLogStatement, which covers all cases regardless of the logging framework. -
The Java rule
UnsynchronizedStaticDateFormatterhas been deprecated and will be removed with PMD 7.0.0. The rule is replaced by the more generalUnsynchronizedStaticFormatter.