diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index dda829b7eb..03e17c841b 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -14,6 +14,18 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy +#### New rules + +* The new Java rule {% rule "java/codestyle/FinalParameterInAbstractMethod" %} detects parameters that are + declared as final in interfaces or abstract methods. Declaring the parameters as final is useless + because the implementation may choose to not respect it. + +```xml + +``` + + The rule is part of the quickstart.xml ruleset. + #### Modified rules * The Apex rule {% rule "apex/documentation/ApexDoc" %} has a new property `reportProperty`. @@ -43,6 +55,7 @@ This is a {{ site.pmd.release_type }} release. * [#3704](https://github.com/pmd/pmd/pull/3704): \[java] Fix for #3686 - Fix ReturnEmptyCollectionRatherThanNull - [Oleksii Dykov](https://github.com/dykov) * [#3713](https://github.com/pmd/pmd/pull/3713): \[java] Enhance UnnecessaryModifier to support records - [Vincent Galloy](https://github.com/vgalloy) * [#3719](https://github.com/pmd/pmd/pull/3719): \[java] Upgrade log4j to 2.17.1 - [Daniel Paul Searles](https://github.com/squaresurf) +* [#3720](https://github.com/pmd/pmd/pull/3720): \[java] New rule: FinalParameterInAbstractMethod - [Vincent Galloy](https://github.com/vgalloy) * [#3724](https://github.com/pmd/pmd/pull/3724): \[java] Fix for #3686 - fix FinalFieldCouldBeStatic - [Oleksii Dykov](https://github.com/dykov) {% endtocmaker %} diff --git a/pmd-core/src/main/resources/rulesets/releases/6420.xml b/pmd-core/src/main/resources/rulesets/releases/6420.xml new file mode 100644 index 0000000000..0770021fcc --- /dev/null +++ b/pmd-core/src/main/resources/rulesets/releases/6420.xml @@ -0,0 +1,13 @@ + + + + +This ruleset contains links to rules that are new in PMD v6.42.0 + + + + + diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index 95e6477a70..b204e0a9ed 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -541,7 +541,6 @@ return a; - + + + Declaring a method parameter as final for an interface method is useless because the implementation may choose to not respect it. + + 1 + + + + + + + + + + + + + --> + diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/FinalParameterInAbstractMethodTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/FinalParameterInAbstractMethodTest.java new file mode 100644 index 0000000000..1402092c39 --- /dev/null +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/FinalParameterInAbstractMethodTest.java @@ -0,0 +1,11 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.codestyle; + +import net.sourceforge.pmd.testframework.PmdRuleTst; + +public class FinalParameterInAbstractMethodTest extends PmdRuleTst { + // no additional unit tests +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/FinalParameterInAbstractMethod.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/FinalParameterInAbstractMethod.xml new file mode 100644 index 0000000000..a7b02ae104 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/FinalParameterInAbstractMethod.xml @@ -0,0 +1,75 @@ + + + + + Final is not allowed in interface public method + 1 + + Final parameter in abstract method + + + + + + Final is allowed in interface static method + 0 + + + + + Final is allowed in interface private method + 0 + + + + + Final is allowed in interface default method + 0 + + + + + Final is allowed in interface inner class method + 0 + + + + + Final is not allowed in abstract method + 1 + + Final parameter in abstract method + + + + +