What's new in PMD 7.0.0
Apr 1, 2024
- Has a new logo
- Analyzes Java 21 and Java 22 projects with even better type resolution and symbol table support
- Analyzes Kotlin and Swift
- Analyzes Apex with a new parser
- Finds duplicated code in Coco, Julia, TypeScript
- Ships 11 new rules and tons of improvements for existing rules
- Provides a new CLI interface with progress bar
- Supports Antlr based languages
- And many more enhancements
New in PMD 7.0.0 RC 4 (Oct 1, 2023)
- New and Noteworthy:
- Migration Guide for PMD 7:
- A detailed documentation of required changes are available in the
- Migration Guide for PMD 7.
- Apex Jorje Updated
- With the new version of Apex Jorje, the new language constructs like User Mode Database Operations
- can be parsed now. PMD should now be able to parse Apex code up to version 59.0 (Winter '23).
- Java 21 Support
- This release of PMD brings support for Java 21. There are the following new standard language features,
- that are supported now:
- JEP 440: Record Patterns
- JEP 441: Pattern Matching for switch
- PMD also supports the following preview language features:
- JEP 430: String Templates (Preview)
- JEP 443: Unnamed Patterns and Variables (Preview)
- JEP 445: Unnamed Classes and Instance Main Methods (Preview)
- 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 21-preview:
- export PMD_JAVA_OPTS=--enable-preview
- pmd check --use-version java-21-preview ...
- Note: Support for Java 19 preview language features have been removed. The version "19-preview" is no longer available.
- Fixed issues:
- miscellaneous:
- 4582: [dist] Download link broken
- 4691: [CVEs] Critical and High CEVs reported on PMD and PMD dependencies
- core:
- 1204: [core] Allow numeric properties in XML to be within an unbounded range
- 3919: [core] Merge CPD and PMD language
- 4204: [core] Provide a CpdAnalysis class as a programmatic entry point into CPD
- 4301: [core] Remove deprecated property concrete classes
- 4302: [core] Migrate Property Framework API to Java 8
- 4323: [core] Refactor CPD integration
- 4397: [core] Refactor CPD
- 4611: [core] Fix loading language properties from env vars
- 4621: [core] Make ClasspathClassLoader::getResource child first
- cli:
- 4423: [cli] Fix NPE when only --file-list is specified
- doc:
- 4294: [doc] Migration Guide for upgrading PMD 6 ?? 7
- 4303: [doc] Document new property framework
- 4521: [doc] Website is not mobile friendly
- apex:
- 3973: [apex] Update parser to support new 'as user' keywords (User Mode for Database Operations)
- 4453: [apex] [7.0-rc1] Exception while initializing Apexlink (Index 34812 out of bounds for length 34812)
- apex-design:
- 4596: [apex] ExcessivePublicCount ignores properties
- apex-security:
- 4646: [apex] ApexSOQLInjection does not recognise SObjectType or SObjectField as safe variable types
- java:
- 4401: [java] PMD 7 fails to build under Java 19
- 4583: [java] Support JDK 21 (LTS)
- java-bestpractices:
- 4634: [java] JUnit4TestShouldUseTestAnnotation false positive with TestNG
- API Changes:
- pmd-java:
- Support for Java 19 preview language features have been removed. The version "19-preview" is no longer available.
- Rule properties:
- The old deprecated classes like IntProperty and StringProperty have been removed. Please use
- PropertyFactory to create properties.
- All properties which accept multiple values now use a comma (,) as a delimiter. The previous default was a
- pipe character (|). The delimiter is not configurable anymore. If needed, the comma can be escaped
- with a backslash.
- The min and max attributes in property definitions in the XML are now optional and can appear separately
- or be omitted.
- New Programmatic API for CPD:
- See Detailed Release Notes for PMD 7
- and PR #4397 for details.
- Removed classes and methods
- The following previously deprecated classes have been removed:
- pmd-core
- net.sourceforge.pmd.cpd.AbstractTokenizer ?? use AnyTokenizer instead
- net.sourceforge.pmd.cpd.CPD ?? use PmdCli from pmd-cli module for CLI support or use
- CpdAnalysis for programmatic API
- net.sourceforge.pmd.cpd.GridBagHelper (now package private)
- net.sourceforge.pmd.cpd.TokenEntry.State
New in PMD 7.0.0 RC 3 (May 31, 2023)
- Changes since 7.0.0-rc2:
- New CPD report format cpdhtml-v2.xslt
- Fixed issues
- API Changes
- External Contributions
New in PMD 7.0.0 RC 2 (May 1, 2023)
- Changes since 7.0.0-rc1:
- This section lists the most important changes from the last release candidate.
- The remaining section describes the complete release notes for 7.0.0.
- API Changes:
- Moved the two classes AntlrTokenizer and JavaCCTokenizer from
- internal package into package net.sourceforge.pmd.cpd.impl. These two classes are part of the API and
- are base classes for CPD language implementations.
- AntlrBaseRule is gone in favor of AbstractVisitorRule.
- The classes KotlinInnerNode and SwiftInnerNode
- are package-private now.
- The parameter order of addSourceFile has been swapped
- in order to have the same meaning as in 6.55.0. That will make it easier if you upgrade from 6.55.0 to 7.0.0.
- However, that means, that you need to change these method calls if you have migrated to 7.0.0-rc1 already.
- Updated PMD Designer:
- This PMD release ships a new version of the pmd-designer.
- For the changes, see PMD Designer Changelog.
- Language Related Changes
- New: CPD support for TypeScript
- New: CPD support for Julia
- Rule Changes:
- ImmutableField: the property ignoredAnnotations has been removed. The property was
- deprecated since PMD 6.52.0.
- SwitchDensity: the type of the property minimum has been changed from decimal to integer
- for consistency with other statistical rules.
- Fixed Issues:
- cli
- 4482: [cli] pmd.bat can only be executed once
- 4484: [cli] ast-dump with no properties produce an NPE
- core
- 2500: [core] Clarify API for ANTLR based languages
- doc
- 2501: [doc] Verify ANTLR Documentation
- 4438: [doc] Documentation links in VS Code are outdated
- java-codestyle
- 4273: [java] CommentDefaultAccessModifier ignoredAnnotations should include "org.junit.jupiter.api.extension.RegisterExtension" by default
- 4487: [java] UnnecessaryConstructor: false-positive with @Inject and @Autowired
- java-design
- 4254: [java] ImmutableField - false positive with Lombok @Setter
- 4477: [java] SignatureDeclareThrowsException: false-positive with TestNG annotations
- 4490: [java] ImmutableField - false negative with Lombok @Getter
- java-errorprone
- 4449: [java] AvoidAccessibilityAlteration: Possible false positive in AvoidAccessibilityAlteration rule when using Lambda expression
- 4493: [java] MissingStaticMethodInNonInstantiatableClass: false-positive about @Inject
- 4505: [java] ImplicitSwitchFallThrough NPE in PMD 7.0.0-rc1
- java-multithreading
- 4483: [java] NonThreadSafeSingleton false positive with double-checked locking
- miscellaneous
- 4462: Provide Software Bill of Materials (SBOM)
- External contributions:
- 4402: [javascript] CPD: add support for Typescript using antlr4 grammar - Paul Guyot (@pguyot)
- 4403: [julia] CPD: Add support for Julia code duplication - Wener (@wener-tiobe)
- 4444: [java] CommentDefaultAccessModifier - ignore org.junit.jupiter.api.extension.RegisterExtension by default - Nirvik Patel (@nirvikpatel)
- 4450: [java] Fix #4449 AvoidAccessibilityAlteration: Correctly handle Lambda expressions in PrivilegedAction scenarios - Seren (@mohui1999)
- 4452: [doc] Update PMD_APEX_ROOT_DIRECTORY documentation reference - nwcm (@nwcm)
- 4474: [java] ImmutableField: False positive with lombok (fixes #4254) - Pim van der Loos (@PimvanderLoos)
- 4488: [java] Fix #4477: A false-positive about SignatureDeclareThrowsException - AnnaDev (@LynnBroe)
- 4494: [java] Fix #4487: A false-positive about UnnecessaryConstructor and @Inject and @Autowired - AnnaDev (@LynnBroe)
- 4495: [java] Fix #4493: false-positive about MissingStaticMethodInNonInstantiatableClass and @Inject - AnnaDev (@LynnBroe)
- 4520: [doc] Fix typo: missing closing quotation mark after CPD-END - João Dinis Ferreira (@joaodinissf)
New in PMD 7.0.0 RC 1 (Mar 27, 2023)
- Major Features and Enhancements:
- New PMD Logo:
- Revamped Java module:
- Java grammar substantially refactored - more correct regarding the Java Language Specification (JLS)
- Built-in rules have been upgraded for the changed AST
- Rewritten type resolution framework and symbol table correctly implements the JLS
- AST exposes more semantic information (method calls, field accesses)
- For more information, see the Detailed Release Notes for PMD 7.
- Contributors: Clément Fournier (@oowekyala),
- Andreas Dangel (@adangel),
- Juan Martín Sotuyo Dodero (@jsotuyod)
- Revamped Command Line Interface:
- unified and consistent Command Line Interface for both Linux/Unix and Windows across our different utilities
- single script pmd (pmd.bat for Windows) to launch the different utilities:
- pmd check to run PMD rules and analyze a project
- pmd cpd to run CPD (copy paste detector)
- pmd designer to run the PMD Rule Designer
- progress bar support for pmd check
- shell completion
- For more information, see the Detailed Release Notes for PMD 7.
- Contributors: Juan Martín Sotuyo Dodero (@jsotuyod)
- Full Antlr support
- Antlr based grammars can now be used to build full-fledged PMD rules.
- Previously, Antlr grammar could only be used for CPD
- New supported languages: Swift and Kotlin
- For more information, see the Detailed Release Notes for PMD 7.
- Contributors: Lucas Soncini (@lsoncini),
- Matías Fraga (@matifraga),
- Tomás De Lucca (@tomidelucca)
- Language Related Changes:
- Note that this is just a concise listing of the highlight.
- For more information on the languages, see the Detailed Release Notes for PMD 7.
- New: Swift support:
- use PMD to analyze Swift code with PMD rules
- initially 4 built-in rules
- Contributors: Lucas Soncini (@lsoncini),
- Matías Fraga (@matifraga),
- Tomás De Lucca (@tomidelucca)
- New: Kotlin support (experimental)
- use PMD to analyze Kotlin code with PMD rules
- Support for Kotlin 1.8 grammar
- initially 2 built-in rules
- Changed: JavaScript support:
- latest version supports ES6 and also some new constructs (see Rhino])
- comments are retained
- Changed: Language versions:
- more predefined language versions for each supported language
- can be used to limit rule execution for specific versions only with minimumLanguageVersion and
- maximumLanguageVersion attributes.
- New and changed rules:
- New Rules:
- Apex:
- UnusedMethod finds unused methods in your code.
- Java:
- UnnecessaryBoxing reports boxing and unboxing conversions that may be made implicit.
- Kotlin:
- FunctionNameTooShort
- OverrideBothEqualsAndHashcode
- Swift:
- ProhibitedInterfaceBuilder
- UnavailableFunction
- ForceCast
- ForceTry
- Changed Rules:
- Java:
- UnnecessaryFullyQualifiedName: the rule has two new properties,
- to selectively disable reporting on static field and method qualifiersThe rule also has been improved
- to be more precise.
- UselessParentheses: the rule has two new properties which control how strict
- the rule should be appliedWith ignoreClarifying (default: true) parentheses that are strictly speaking
- not necessary are allowed, if they separate expressions of different precedence.
- The other property ignoreBalancing (default: true) is similar, in that it allows parentheses that help
- reading and understanding the expressions.
- LooseCoupling: the rule has a new property to allow some types to be coupled
- to (allowedTypes).
- EmptyCatchBlock: CloneNotSupportedException and InterruptedException are not
- special-cased anymoreRename the exception parameter to ignored to ignore them.
- DontImportSun: sun.misc.Signal is not special-cased anymore.
- UseDiamondOperator: the property java7Compatibility is removedThe rule now
- handles Java 7 properly without a property.
- SingularField: Properties checkInnerClasses and disallowNotAssignment are removed.
- The rule is now more precise and will check these cases properly.
- UseUtilityClass: The property ignoredAnnotations has been removed.
- LawOfDemeter: the rule has a new property trustRadiusThis defines the maximum degree
- of trusted dataThe default of 1 is the most restrictive.
- CommentContent: The properties caseSensitive and disallowedTerms are removedThe
- new property fobiddenRegex can be used now to define the disallowed terms with a single regular
- expression.
- Removed Rules:
- Many rules, that were previously deprecated have been finally removed.
- See Detailed Release Notes for PMD 7 for the complete list.
- API:
- The API of PMD has been growing over the years and needed some cleanupThe goal is, to
- have a clear separation between a well-defined API and the implementation, which is internal.
- This should help us in future development.
- Also, there are some improvement and changes in different areasFor the detailed description
- of the changes listed here, see Detailed Release Notes for PMD 7.
- Miscellaneous smaller changes and cleanups
- XPath 3.1 support for XPath-based rules
- Node stream API for AST ...
New in PMD 6.55.0 (Feb 26, 2023)
- T-SQL support:
- Thanks to the contribution from Paul Guyot PMD now has CPD support
- for T-SQL (Transact-SQL).
- Being based on a proper Antlr grammar, CPD can:
- ignore comments
- honor comment-based suppressions
- Fixed Issues:
- core:
- #4395: [core] Support environment variable CLASSPATH with pmd.bat under Windows
- java:
- #4333: [java] Support JDK 20
- java-errorprone
- #4393: [java] MissingStaticMethodInNonInstantiatableClass false-positive for Lombok's @UtilityClass for classes with non-private fields
- API Changes:
- Go:
- The LanguageModule of Go, that only supports CPD execution, has been deprecated. This language
- is 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 class has been deprecated and will be removed with PMD 7.0.0:
- GoLanguageModule
- Java:
- Support for Java 18 preview language features have been removed. The version "18-preview" is no longer available.
- The experimental class net.sourceforge.pmd.lang.java.ast.ASTGuardedPattern has been removed.
New in PMD 6.54.0 (Feb 11, 2023)
- New and noteworthy:
- New report format html-report-v2.xslt:
- Thanks to @mohan-chinnappan-n a new PMD report format has been added which features a data table with charting functions. It uses an XSLT stylesheet to convert PMD’s XML format into HTML.
- See the example report.
- Fixed Issues:
- apex-bestpractices
- 2669: [apex] UnusedLocalVariable false positive in dynamic SOQL
- core
- 4026: [cli] Filenames printed as absolute paths in the report despite parameter --short-names
- 4279: [core] Can not set ruleset property value to empty
- 4329: [core] Refactor usage of snakeyaml
- 4340: [core] Allow to filter found matches in CPDReport
- java
- 4364: [java] Parsing error with textblock containing quote followed by two backslashes
- testing
- 4236: [test] kotest logs look broken
- API Changes:
- PMD CLI:
- PMD now supports a new --relativize-paths-with flag (or short -z), which replaces --short-names. It serves the same purpose: Shortening the pathnames in the reports. However, with the new flag it’s possible to explicitly define one or more pathnames that should be used as the base when creating relative paths. The old flag --short-names is deprecated.
- Deprecated APIs:
- For removal:
- ApexRootNode#getApexVersion has been deprecated for removal. The version returned is always Version.CURRENT, as the apex compiler integration doesn’t use additional information which Apex version actually is used. Therefore, this method can’t be used to determine the Apex version of the project that is being analyzed.
- CPDConfiguration#setEncoding and CPDConfiguration#getEncoding. Use the methods getSourceEncoding and setSourceEncoding instead. Both are available for CPDConfiguration which extends AbstractConfiguration.
- BaseCLITest and BaseCPDCLITest have been deprecated for removal without replacement. CLI tests should be done in pmd-core only (and in PMD7 in pmd-cli). Individual language modules shouldn’t need to test the CLI integration logic again. Instead, the individual language modules should test their functionality as unit tests.
- CPDConfiguration.LanguageConverter
- FileCollector#addZipFile has been deprecated. It is replaced by FileCollector#addZipFileWithContent which directly adds the content of the zip file for analysis.
- PMDConfiguration#setReportShortNames and PMDConfiguration#isReportShortNames have been deprecated for removal. Use PMDConfiguration#addRelativizeRoot instead.
- Internal APIs:
- CSVWriter
- Some fields in AbstractAntTestHelper
- Experimental APIs:
- CPDReport has a new method which limited mutation of a given report:
- filterMatches creates a new CPD report with some matches removed with a given predicate based filter.
- External Contributions:
- 4110: [apex] Feature/unused variable bind false positive with dynamic SOQL - Thomas Prouvot (@tprouvot)
- 4125: [core] New report format html-report-v2.xslt to provide html with datatable and chart features - Mohan Chinnappan - (@mohan-chinnappan-n)
- 4280: [apex] Deprecate ApexRootNode.getApexVersion - Aaron Hurst (@aaronhurst-google)
- 4285: [java] CommentDefaultAccessModifier - add co.elastic.clients.util.VisibleForTesting as default suppressed annotation - Matthew Luckam (@mluckam)
- Stats:
- 107 commits
- 19 closed tickets & PRs
- Days since last release: 27
New in PMD 6.37.0 (Jul 31, 2021)
- New and noteworthy:
- Java 17 Support
- This release of PMD brings support for Java 17. PMD supports JEP 409: Sealed
- Classes which has been promoted to be a standard language feature of Java 17.
- PMD also supports JEP 406: Pattern Matching for switch (Preview) as a preview
- Language feature. 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 17-preview:
- Export PMD_JAVA_OPTS=--enable-preview
- ./run.sh pmd -language java -version 17-preview ...
- Note: Support for Java 15 preview language features have been removed. The version "15-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.
- New rules
- This release ships with 3 new Java rules.
- PrimitiveWrapperInstantiation reports usages of primitive wrapper constructors. They are deprecated since Java 9 and should not be used.
- <rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" />
- The rule is part of the quickstart.xml ruleset.
- SimplifiableTestAssertion suggests rewriting some test assertions to be more readable.
- <rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
- The rule is part of the quickstart.xml ruleset.
- ReturnEmptyCollectionRatherThanNull suggests returning empty collections / arrays instead of null.
- <rule ref="category/java/errorprone.xml/ReturnEmptyCollectionRatherThanNull" />
- The rule is part of the quickstart.xml ruleset.
- Renamed rules
- The Java rule MissingBreakInSwitch has been renamed to
- ImplicitSwitchFallThrough (category error prone) to better reflect the rule's purpose: The rule finds implicit fall-through cases in switch statements, which are most
- Likely unexpected. The old rule name described only one way how to avoid a fall-through, namely using break but continue, throw and return avoid a fall-through as well. This enables us to improve this rule in the future.
- Deprecated rules:
- The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule SimplifiableTestAssertion merges their functionality:
- UseAssertEqualsInsteadOfAssertTrue
- UseAssertNullInsteadOfAssertTrue
- UseAssertSameInsteadOfAssertTrue
- UseAssertTrueInsteadOfAssertEquals
- SimplifyBooleanAssertion
- The Java rule ReturnEmptyArrayRatherThanNull is deprecated and removed from the quickstart ruleset, as the new rule ReturnEmptyCollectionRatherThanNull supersedes it.
- The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule PrimitiveWrapperInstantiation merges their functionality:
- BooleanInstantiation
- ByteInstantiation
- IntegerInstantiation
- LongInstantiation
- ShortInstantiation
- The Java rule UnnecessaryWrapperObjectCreation is deprecated with no planned replacement before PMD 7. In it's current state, the rule is not useful as it finds only contrived cases of creating a primitive wrapper and unboxing it explicitly in the same expression. In PMD 7 this and more cases will be covered by a new rule UnnecessaryBoxing.
- Fixed Issues:
- Apex
- #3201: [apex] ApexCRUDViolation doesn't report Database class DMLs, inline no-arg object instantiations and inline list initialization
- #3329: [apex] ApexCRUDViolation doesn't report SOQL for loops core
- #1603: [core] Language version comparison
- #2133: [xml] Allow to check Salesforce XML Metadata using XPath rules
- #3377: [core] NPE when specifying report file in current directory in PMD CLI
- #3387: [core] CPD should avoid unnecessary copies when running with --skip-lexical-errors
- Java-bestpractices
- #2908: [java] Merge Junit assertion simplification rules
- #3235: [java] UseTryWithResources false positive when closeable is provided as a method argument or class field
- Java-errorprone
- #3361: [java] Rename rule MissingBreakInSwitch to ImplicitSwitchFallThrough
- #3382: [java] New rule ReturnEmptyCollectionRatherThanNull
- Java-performance
- #3420: [java] NPE in InefficientStringBuffering with Records
- API Changes
- PMD CLI
- PMD has a new CLI option -force-language. With that a language can be forced to be used for all input files, irrespective of filenames. When using this option, the automatic language selection by extension is disabled and all files are tried to be parsed with the given language. Parsing errors are ignored and unparsable files are skipped.
- This option allows to use the xml language for files, that don't use xml as extension.
- See also the examples on PMD CLI reference.
- Experimental APIs:
- The AST types and APIs around Sealed Classes are not experimental anymore:
- ASTClassOrInterfaceDeclaration#isSealed,
- ASTClassOrInterfaceDeclaration#isNonSealed,
- ASTClassOrInterfaceDeclaration#getPermittedSubclasses
- ASTPermitsList
- 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.
- The inner class net.sourceforge.pmd.cpd.TokenEntry.State is considered to be internal API.
- It will probably be moved away with PMD 7.
New in PMD 6.32.0 (Mar 9, 2021)
- New and noteworthy:
- Java 16 Support:
- This release of PMD brings support for Java 16. PMD supports JEP 394: Pattern Matching for instanceof and JEP 395: Records. Both have been promoted to be a standard language feature of Java 16.
- PMD also supports JEP 397: Sealed Classes (Second Preview) as a preview language feature. 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 16-preview:
- export PMD_JAVA_OPTS=--enable-preview
- ./run.sh pmd -language java -version 16-preview ...
- Note: Support for Java 14 preview language features have been removed. The version “14-preview” is no longer available.
- Modified Rules:
- The Apex rule ApexDoc has two new properties: reportPrivate and reportProtected. Previously the rule only considered public and global classes, methods, and properties. With these properties, you can verify the existence of ApexDoc comments for private and protected methods as well. By default, these properties are disabled to preserve backwards compatible behavior.
- Fixed Issues:
- apex-documentation
- 3075: [apex] ApexDoc should support private access modifier
- java
- 3101: [java] NullPointerException when running PMD under JRE 11
- java-bestpractices
- 3132: [java] UnusedImports with static imports on subclasses
- java-errorprone
- 2716: [java] CompareObjectsWithEqualsRule: False positive with Enums
- 3089: [java] CloseResource rule throws exception on spaces in property types
- 3133: [java] InvalidLogMessageFormat FP with StringFormattedMessage and ParameterizedMessage
- plsql
- 3106: [plsql] ParseException while parsing EXECUTE IMMEDIATE ‘drop database link ‘ || linkname;
- API Changes:
- Experimental APIs:
- The experimental class ASTTypeTestPattern has been renamed to ASTTypePattern in order to align the naming to the JLS.
- The experimental class ASTRecordConstructorDeclaration has been renamed to ASTCompactConstructorDeclaration in order to align the naming to the JLS.
- The AST types and APIs around Pattern Matching and Records are not experimental anymore:
- ASTVariableDeclaratorId#isPatternBinding
- ASTPattern
- ASTTypePattern
- ASTRecordDeclaration
- ASTRecordComponentList
- ASTRecordComponent
- ASTRecordBody
- ASTCompactConstructorDeclaration
- 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.
- The protected or public member of the Java rule AvoidUsingHardCodedIPRule are deprecated and considered to be internal API. They will be removed with PMD 7.
New in PMD 6.30.0 (Dec 12, 2020)
- New and noteworthy:
- CPD:
- The C# module now supports the new option --ignore-literal-sequences, which can be used to avoid detection of some uninteresting clones. Support for other languages may be added in the future. See #2945
- The Scala module now supports suppression through CPD-ON/CPD-OFF comment pairs. See #2929
- Type information for VisualForce:
- The Visualforce AST now can resolve the data type of Visualforce expressions that reference Apex Controller properties and Custom Object fields. This feature improves the precision of existing rules, like VfUnescapeEl.
- This can be configured using two environment variables:
- Comma separated list of directories for Apex classes. Absolute or relative to the Visualforce directory. Default is ../classes. Specifying an empty string will disable data type resolution for Apex Controller properties.
- Comma separated list of directories for Custom Objects. Absolute or relative to the Visualforce directory. Default is ../objects. Specifying an empty string will disable data type resolution for Custom Object fields.
- This feature is experimental, in particular, expect changes to the way the configuration is specified. We’ll probably extend the CLI instead of relying on environment variables in a future version.
- Fixed Issues:
- core:
- #1939: [core] XPath expressions return handling
- #1961: [core] Text renderer should include name of violated rule
- #2874: [core] Fix XMLRenderer with UTF-16
- cs:
- #2938: [cs] CPD: ignoring using directives could not be disabled
- java:
- #2911: [java] ClassTypeResolver#searchNodeNameForClass leaks memory
- #2934: [java] CompareObjectsWithEquals / UseEqualsToCompareStrings - False negatives with fields
- #2940: [java] Catch additional TypeNotPresentExceptions / LinkageErrors
- scala:
- #2480: [scala] Support CPD suppressions
- API Changes:
- Deprecated API:
- Around RuleSet parsing:
- RuleSetFactory and RuleSetFactoryUtils have been deprecated in favor of RuleSetLoader. This is easier to configure, and more maintainable than the multiple overloads of RuleSetFactoryUtils.
- Some static creation methods have been added to RuleSet for simple cases, eg forSingleRule. These replace some counterparts in RuleSetFactory
- Since RuleSets is also deprecated, many APIs that require a RuleSets instance now are deprecated, and have a counterpart that expects a List<RuleSet>.
- RuleSetReferenceId, RuleSetReference, RuleSetFactoryCompatibility are deprecated. They are most likely not relevant outside of the implementation of pmd-core.
- Around the PMD class:
- Many classes around PMD’s entry point (PMD) have been deprecated as internal, including:
- The contents of the packages net.sourceforge.pmd.cli, net.sourceforge.pmd.processor
- SourceCodeProcessor
- The constructors of PMD (the class will be made a utility class)
- Miscellaneous:
- ASTPackageDeclaration#getPackageNameImage, ASTTypeParameter#getParameterName and the corresponding XPath attributes. In both cases they’re replaced with a new method getName, the attribute is @Name.
- ASTClassOrInterfaceBody#isAnonymousInnerClass, and ASTClassOrInterfaceBody#isEnumChild, refs #905
- 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.
- net.sourceforge.pmd.lang.ecmascript.Ecmascript3Handler
- net.sourceforge.pmd.lang.ecmascript.Ecmascript3Parser
- EcmascriptParser#parserOptions
- EcmascriptParser#getSuppressMap
- net.sourceforge.pmd.lang.rule.ParametricRuleViolation
- ParserOptions#suppressMarker
- net.sourceforge.pmd.lang.modelica.rule.ModelicaRuleViolationFactory
- External Contributions:
- #2864: [vf] Provide expression type information to Visualforce rules to avoid false positives - Jeff Bartolotta
- #2914: [core] Include rule name in text renderer - Gunther Schrijvers
- #2925: Cleanup: Correct annotation array initializer indents from checkstyle #8083 - Abhishek Kumar
- #2929: [scala] Add support for CPD-ON and CPD-OFF special comments - Andy Robinson
- #2936: [java] (doc) Fix typo: “an accessor” not “a” - Igor Moreno
- #2938: [cs] CPD: fix issue where ignoring using directives could not be disabled - Maikel Steneker
- #2945: [cs] Add option to ignore sequences of literals - Maikel Steneker
- #2962: [cpp] Add support for C++ 14 binary literals - Maikel Steneker
- Stats:
- 190 commits
- 25 closed tickets & PRs
- Days since last release: 49
New in PMD 6.29.0 (Oct 24, 2020)
- New and noteworthy:
- Updated Apex Support:
- The Apex language support has been bumped to version 50 (Winter ‘21). All new language features are now properly parsed and processed. Especially the Safe Navigation Operator is now supported. See also Salesforce Winter ‘21 Release Notes
- New Rules:
- The new Apex rule OperationWithLimitsInLoop (apex-performance) finds operations in loops that may hit governor limits such as DML operations, SOQL queries and more. The rule replaces the three rules “AvoidDmlStatementsInLoops”, “AvoidSoqlInLoops”, and “AvoidSoslInLoops”.
- Renamed Rules:
- The Java rule DoNotCallSystemExit has been renamed to DoNotTerminateVM, since it checks for all the following calls: System.exit(int), Runtime.exit(int), Runtime.halt(int). All these calls terminate the Java VM, which is bad, if the VM runs an application server which many independent applications.
- Deprecated Rules:
- The Apex rules AvoidDmlStatementsInLoops, AvoidSoqlInLoops and AvoidSoslInLoops (apex-performance) are deprecated in favour of the new rule OperationWithLimitsInLoop. The deprecated rules will be removed with PMD 7.0.0.
- Fixed Issues:
- apex:
- #2839: [apex] Apex classes with safe navigation operator from Winter 21 (50.0) are skipped
- apex-performance
- #1713: [apex] Mark Database DML statements in For Loop
- core:
- #2831: [core] Fix XMLRenderer newlines when running under IBM Java
- java-errorprone
- #2157: [java] Improve DoNotCallSystemExit: permit call in main(), flag System.halt:
- #2764: [java] CloseResourceRule does not recognize multiple assignment done to resource
- miscellaneous:
- #2823: [doc] Renamed/Moved rules are missing in documentation
- vf (Salesforce VisualForce)
- #2765: [vf] Attributes with dot cause a VfParseException
- External Contributions:
- #2803: [java] Improve DoNotCallSystemExit (Fixes #2157) - Vitaly Polonetsky
- #2809: [java] Move test config from file to test class - Stefan Birkner
- #2810: [core] Move method “renderTempFile” to XMLRendererTest - Stefan Birkner
- #2811: [java] CloseResource - Fix #2764: False-negative when re-assigning variable - Andi Pabst
- #2813: [core] Use JUnit’s TemporaryFolder rule - Stefan Birkner
- #2816: [apex] Detect ‘Database’ method invocations inside loops - Jeff Bartolotta
- #2829: [doc] Small correction in pmd_report_formats.md - Gustavo Krieger
- #2834: [vf] Allow attributes with dot in Visualforce - rmohan20
- #2842: [core] Bump antlr4 from 4.7 to 4.7.2 - Adrien Lecharpentier
- #2865: [java] (doc) Update ExcessiveImports example code for clarity - Gustavo Krieger
- #2866: [java] (doc) Fix example for CouplingBetweenObjects - Gustavo Krieger
- Stats:
- 50 commits
- 23 closed tickets & PRs
- Days since last release: 27
New in PMD 6.27.0 (Sep 27, 2020)
- New and noteworthy:
- CPD’s AnyTokenizer has been improved
- The AnyTokenizer is used for languages, that don’t have an own lexer/grammar based tokenizer. AnyTokenizer now handles string literals and end-of-line comments. Fortran, Perl and Ruby have been updated to use AnyTokenizer instead of their old custom tokenizer based on AbstractTokenizer. See #2758 for details.
- AbstractTokenizer and the custom tokenizers of Fortran, Perl and Ruby are deprecated now.
- Fixed Issues:
- cpd:
- 2758: [cpd] Improve AnyTokenizer
- 2760: [cpd] AnyTokenizer doesn’t count columns correctly
- apex-security
- 2774: [apex] ApexSharingViolations does not correlate sharing settings with class that contains data access
- java
- 2738: [java] Custom rule with @ExhaustiveEnumSwitch throws NPE
- 2755: [java] [6.27.0] Exception applying rule CloseResource on file … java.lang.NullPointerException
- 2756: [java] TypeTestUtil fails with NPE for anonymous class
- 2767: [java] IndexOutOfBoundsException when parsing an initializer BlockStatement
- 2783: [java] Error while parsing with lambda of custom interface
- java-bestpractices
- 2759: [java] False positive in UnusedAssignment
- java-design
- 2708: [java] False positive FinalFieldCouldBeStatic when using lombok Builder.Default
- API Changes:
- Deprecated API:
- For removal:
- net.sourceforge.pmd.RuleViolationComparator. Use RuleViolation#DEFAULT_COMPARATOR instead.
- net.sourceforge.pmd.cpd.AbstractTokenizer. Use net.sourceforge.pmd.cpd.AnyTokenizer instead.
- net.sourceforge.pmd.cpd.FortranTokenizer. Was replaced by an AnyTokenizer. Use FortranLanguage#getTokenizer anyway.
- net.sourceforge.pmd.cpd.PerlTokenizer. Was replaced by an AnyTokenizer. Use PerlLanguage#getTokenizer anyway.
- net.sourceforge.pmd.cpd.RubyTokenizer. Was replaced by an AnyTokenizer. Use RubyLanguage#getTokenizer anyway.
- RuleReference#getOverriddenLanguage and RuleReference#setLanguage
- Antlr4 generated lexers:
- net.sourceforge.pmd.lang.cs.antlr4.CSharpLexer will be moved to package net.sourceforge.pmd.lang.cs.ast with PMD 7.
- net.sourceforge.pmd.lang.dart.antlr4.Dart2Lexer will be renamed to DartLexer and moved to package net.sourceforge.pmd.lang.dart.ast with PMD 7. All other classes in the old package will be removed.
- net.sourceforge.pmd.lang.go.antlr4.GolangLexer will be moved to package net.sourceforge.pmd.lang.go.ast with PMD 7. All other classes in the old package will be removed.
- net.sourceforge.pmd.lang.kotlin.antlr4.Kotlin will be renamed to KotlinLexer and moved to package net.sourceforge.pmd.lang.kotlin.ast with PMD 7.
- net.sourceforge.pmd.lang.lua.antlr4.LuaLexer will be moved to package net.sourceforge.pmd.lang.lua.ast with PMD 7. All other classes in the old package will be removed.
- External Contributions:
- 2735: [ci] Add github actions for a fast view of pr succeed/not - XenoAmess
- 2747: [java] Don’t trigger FinalFieldCouldBeStatic when field is annotated with lombok @Builder.Default - Ollie Abbey
- 2773: [java] issue-2738: Adding null check to avoid npe when switch case is default - Nimit Patel
- 2789: Add badge for reproducible build - Dan Rollo
- 2791: [apex] Analyze inner classes for sharing violations - Jeff Bartolotta
New in PMD 6.27.0 (Sep 1, 2020)
- New and noteworthy:
- Java 15 Support:
- This release of PMD brings support for Java 15. PMD can parse Text Blocks which have been promoted to be a standard language feature of Java.
- PMD also supports Pattern Matching for instanceof, Records, and Sealed Classes.
- Note: The Pattern Matching for instanceof, Records, and Sealed Classes are all preview language features of OpenJDK 15 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 15-preview:
- export PMD_JAVA_OPTS=--enable-preview
- ./run.sh pmd -language java -version 15-preview ...
- Note: Support for Java 13 preview language features have been removed. The version "13-preview" is no longer available.
- Changes in how tab characters are handled
- In the past, tab characters in source files has been handled differently in different languages by PMD. For instance in Java, tab characters had a width of 8 columns, while C# used only 1 column. Visualforce instead used 4 columns.
- This has been unified now so that tab characters are consistently now always 1 column wide.
- This however might be a incompatible change, if you're using the properties "BeginColumn" or "EndColumn" additionally to "BeginLine" and "EndLine" of a Token/AST node in order to highlight where a rule violation occurred in the source file. If you have logic there that deals with tab characters, you most likely can remove this logic now, since tab characters are now just "normal" characters in terms of string processing.
- See also [all] Ensure PMD/CPD uses tab width of 1 for tabs consistently #2656.
- 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 AvoidReassigningCatchVariables (java-bestpractices) finds cases where the variable of the caught exception is reassigned. This practice is surprising and prevents further evolution of the code like multi-catch.
- Modified Rules:
- The Java rule CloseResource (java-errorprone) has a new property closeNotInFinally. With this property set to true the rule will also find calls to close a resource, which are not in a finally-block of a try-statement. If a resource is not closed within a finally block, it might not be closed at all in case of exceptions.
- As this new detection would yield many new violations, it is disabled by default. It might be enabled in a later version of PMD.
- Deprecated Rules:
- The Java rule DataflowAnomalyAnalysis (java-errorprone) is deprecated in favour of UnusedAssignment (java-bestpractices), which was introduced in PMD 6.26.0.
- Fixed Issues:
- core:
- 724: [core] Avoid parsing rulesets multiple times
- 1962: [core] Simplify Report API
- 2653: [lang-test] Upgrade kotlintest to Kotest
- 2656: [all] Ensure PMD/CPD uses tab width of 1 for tabs consistently
- 2690: [core] Fix java7 compatibility
- java:
- 2646: [java] Support JDK 15
- java-bestpractices:
- 2471: [java] New Rule: AvoidReassigningCatchVariables
- 2663: [java] NoClassDefFoundError on upgrade from 6.25.0 to 6.26.0
- 2668: [java] UnusedAssignment false positives
- 2673: [java] UnusedPrivateField and SingularField false positive with lombok annotation EqualsAndHashCode
- 2684: [java] UnusedAssignment FP in try/catch
- 2686: [java] UnusedAssignment must not flag abstract method parameters in interfaces and abstract classes
- java-design:
- 2108: [java] [doc] ImmutableField rule: Description should clarify shallow immutability
- 2461: [java] ExcessiveParameterListRule must ignore a private constructor
- java-errorprone:
- 2264: [java] SuspiciousEqualsMethodName: Improve description about error-prone overloading of equals()
- 2410: [java] ProperCloneImplementation not valid for final class
- 2431: [java] InvalidLogMessageFormatRule throws IndexOutOfBoundsException when only logging exception message
- 2439: [java] AvoidCatchingThrowable can not detect the case: catch (java.lang.Throwable t)
- 2470: [java] CloseResource false positive when resource included in return value
- 2531: [java] UnnecessaryCaseChange can not detect the case like: foo.equals(bar.toLowerCase())
- 2647: [java] Deprecate rule DataFlowAnomalyAnalysis
- java-performance:
- 1868: [java] false-positive for SimplifyStartsWith if string is empty
- 2441: [java] RedundantFieldInitializer can not detect a special case for char initialize: char foo = '