Rename StaticFieldMustBeFinal rule to MutableStaticState
Move MutableStaticState from security to design. Change description to clarify what "visible field" is. Change "since" attribute from 6.34.0 to 6.35.0. Add AssignmentToNonFinalStatic rule reference.
This commit is contained in:
1 parent
fdb1420c5d
commit
dfcf0d01ca
5 files changed
+43
-39
No files matched your search
-11
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.security;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
|
||||
public class StaticFieldMustBeFinal extends AbstractJavaRule {
|
||||
// no additional unit tests
|
||||
}
|
||||
@@ -1727,6 +1727,38 @@ public class MaybeAUtility {
|
||||
public static void foo() {}
|
||||
public static void bar() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="MutableStaticState"
|
||||
language="java"
|
||||
since="6.35.0"
|
||||
message="Do not use non-final non-private static fields"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#mutablestaticstate">
|
||||
<description>
|
||||
Non-private static fields must be made constants (or immutable references) by
|
||||
declaring them final.
|
||||
|
||||
If you are using this rule, then you don't need this
|
||||
rule {% rule java/errorprone/AssignmentToNonFinalStatic %}.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="2.0"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//FieldDeclaration[@Static = true() and @Private = false() and @Final = false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Greeter { public static Foo foo = new Foo(); ... } // avoid this
|
||||
public class Greeter { public static final Foo FOO = new Foo(); ... } // use this instead
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
@@ -60,34 +60,6 @@ public class Foo {
|
||||
byte[] iv = "secret iv in here".getBytes();
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="StaticFieldMustBeFinal"
|
||||
language="java"
|
||||
since="6.34.0"
|
||||
message="Do not use non-final visible static fields"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule">
|
||||
<description>
|
||||
Visible static fields must be made constants (or immutable
|
||||
references) by declaring them final.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="2.0"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//FieldDeclaration[@Static = true() and @Private = false() and @Final = false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Greeter { public static Foo foo = new Foo(); ... } // avoid this
|
||||
public class Greeter { public static final Foo FOO = new Foo(); ... } // use this instead
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.design;
|
||||
|
||||
import net.sourceforge.pmd.testframework.PmdRuleTst;
|
||||
|
||||
public class MutableStaticState extends PmdRuleTst {
|
||||
// no additional unit tests
|
||||
}
|
||||
Reference in new issue
Block a user