From 74f36bf18ef205ab2751f27beb26c1aafecbcd9a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 29 Jun 2019 14:34:36 +0200 Subject: [PATCH] [java] Deprecate AvoidFinalLocalVariable Fixes #1612, Refs #1482 --- docs/pages/release_notes.md | 11 +++++++++++ .../main/resources/category/java/codestyle.xml | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 855a1d241c..af0b321c9c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -59,6 +59,14 @@ Table aliases are now supported when specifying columns in INSERT INTO clauses. non static initializers in anonymous classes anymore. For this use case, there is a new rule now: {% rule "java/bestpractices/DoubleBraceInitialization" %} (`java-bestpractices`). +#### Deprecated Rules + +* The Java rule {% rule "java/codestyle/AvoidFinalLocalVariable" %} (`java-codestyle`) has been deprecated + and will be removed with PMD 7.0.0. The rule is controversial and also contradicts other existing + rules such as {% rule "java/codestyle/LocalVariableCouldBeFinal" %}. If the goal is to avoid defining + constants in a scope smaller than the class, then the rule {% rule "java/errorprone/AvoidDuplicateLiterals" %} + should be used instead. + ### Fixed Issues * apex @@ -69,6 +77,8 @@ Table aliases are now supported when specifying columns in INSERT INTO clauses. * [#1703](https://github.com/pmd/pmd/issues/1703): \[java] UnusedPrivateField on member annotated with lombok @Delegate * [#1845](https://github.com/pmd/pmd/issues/1845): \[java] Regression in MethodReturnsInternalArray not handling enums * [#1854](https://github.com/pmd/pmd/issues/1854): \[java] Rule to check for double brace initialisation +* java-codestyle + * [#1612](https://github.com/pmd/pmd/issues/1612): \[java] Deprecate AvoidFinalLocalVariable * java-design * [#1094](https://github.com/pmd/pmd/issues/1094): \[java] UseUtilityClass should be LombokAware * java-errorprone @@ -110,6 +120,7 @@ of deprecations. ### External Contributions +* [#1482](https://github.com/pmd/pmd/pull/1482): \[java] Explain the existence of AvoidFinalLocalVariable in it's description - [Karl-Philipp Richter](https://github.com/krichter722) * [#1792](https://github.com/pmd/pmd/pull/1792): \[java] Added lombok.experimental to AbstractLombokAwareRule - [jakivey32](https://github.com/jakivey32) * [#1808](https://github.com/pmd/pmd/pull/1808): \[plsql] Fix PL/SQL Syntax errors - [Hugo Araya Nash](https://github.com/kabroxiko) * [#1829](https://github.com/pmd/pmd/pull/1829): \[java] Fix false negative in UnsynchronizedStaticFormatter - [Srinivasan Venkatachalam](https://github.com/Srini1993) diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 87a5bbb276..d6b5793180 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -92,10 +92,24 @@ public class Fo$o { // not a recommended name - + +Avoid using final local variables, turn them into fields. + +Note that this is a controversial rule which is merely useful to enforce a certain code style +(which is contradictory to good coding practices in most of the cases it's applied to) and +avoid local literals being declared in a scope smaller than the class. + +Also note, that this rule is the opposite of {% rule "java/codestyle/LocalVariableCouldBeFinal" %}. +Having both rules enabled results in contradictory violations being reported. + +This rule is deprecated and will be removed with PMD 7.0.0. There is no replacement planned. +If the goal is to avoid defining constants in a scope smaller than the class, then the rule +{% rule "java/errorprone/AvoidDuplicateLiterals" %} should be used instead. + 3