diff --git a/feed.xml b/feed.xml index bea19071d8..9945950393 100644 --- a/feed.xml +++ b/feed.xml @@ -5,8 +5,8 @@ Intended as a documentation theme based on Jekyll for technical writers documenting software and other technical products, this theme has all the elements you would need to handle multiple products with both multi-level sidebar navigation, tags, and other documentation features. https://pmd.github.io/pmd/ - Tue, 25 May 2021 11:37:20 +0000 - Tue, 25 May 2021 11:37:20 +0000 + Tue, 25 May 2021 17:49:39 +0000 + Tue, 25 May 2021 17:49:39 +0000 Jekyll v3.9.0 diff --git a/pmd_release_notes.html b/pmd_release_notes.html index 59fdf509f3..d2964bf2c2 100644 --- a/pmd_release_notes.html +++ b/pmd_release_notes.html @@ -1444,6 +1444,12 @@ to analyze JavaScript code. Note that PMD core still only requires Java 7.

enforces the convention that JUnit 5 tests should have minimal visibility. You can try out this rule like so:
<rule ref="category/java/bestpractices.xml/JUnit5TestShouldBePackagePrivate" />
+
+ +
  • The new Java rule MutableStaticState finds non-private static fields +that are not final. These fields break encapsulation since these fields can be modified from anywhere +within the program. You can try out this rule like so: +
    <rule ref="category/java/design.xml/MutableStaticState" />
     
  • @@ -1524,6 +1530,7 @@ However, Object.clone()#2219: [java] Document Reasons to Avoid Reassigning Parameters
  • #2737: [java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault with non-exhaustive enum switch
  • #3236: [java] LiteralsFirstInComparisons should consider constant fields (cont’d)
  • +
  • #3239: [java] PMD could enforce non-public methods for Junit5 / Jupiter test methods
  • #3254: [java] AvoidReassigningParameters reports violations on wrong line numbers
  • @@ -1541,6 +1548,7 @@ However, Object.clone()java-design
  • java-errorprone @@ -1566,6 +1574,8 @@ However, Object.clone()External Contributions diff --git a/pmd_rules_java.html b/pmd_rules_java.html index 2f67a0872f..385fdea9b8 100644 --- a/pmd_rules_java.html +++ b/pmd_rules_java.html @@ -1588,6 +1588,7 @@ $('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3
  • LogicInversion: Use opposite operator instead of negating the whole expression with a logic complement operator.
  • LoosePackageCoupling: Avoid using classes from the configured package hierarchy outside of the package hierarchy, excep…
  • ModifiedCyclomaticComplexity: Deprecated Complexity directly affects maintenance costs is determined by the number of decision points in a…
  • +
  • MutableStaticState: Non-private static fields should be made constants (or immutable references) by declaring them fi…
  • NcssConstructorCount: Deprecated This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of l…
  • NcssCount: This rule uses the NCSS (Non-Commenting Source Statements) metric to determine the number of line…
  • NcssMethodCount: Deprecated This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of l…
  • diff --git a/pmd_rules_java_design.html b/pmd_rules_java_design.html index 68297d007f..dbfeb089a5 100644 --- a/pmd_rules_java_design.html +++ b/pmd_rules_java_design.html @@ -5,7 +5,7 @@ - + Design | PMD Source Code Analyzer @@ -2777,6 +2777,38 @@ by the rule </rule> +

    MutableStaticState

    + +

    Since: PMD 6.35.0

    + +

    Priority: Medium (3)

    + +

    Non-private static fields should be made constants (or immutable references) by +declaring them final.

    + +

    Non-private non-final static fields break encapsulation and can lead to hard to find +bugs, since these fields can be modified from anywhere within the program. +Callers can trivially access and modify non-private non-final static fields. Neither +accesses nor modifications can be guarded against, and newly set values cannot +be validated.

    + +

    If you are using this rule, then you don’t need this +rule AssignmentToNonFinalStatic.

    + +

    This rule is defined by the following XPath expression:

    +
    //FieldDeclaration[@Static = true() and @Private = false() and @Final = false()]
    +
    + +

    Example(s):

    + +
    public class Greeter { public static Foo foo = new Foo(); ... }       // avoid this
    +public class Greeter { public static final Foo FOO = new Foo(); ... } // use this instead
    +
    + +

    Use this rule by referencing it:

    +
    <rule ref="category/java/design.xml/MutableStaticState" />
    +
    +

    NcssConstructorCount

    Deprecated

    diff --git a/search.json b/search.json index c3b84888ce..3a0bfe01cf 100644 --- a/search.json +++ b/search.json @@ -2730,6 +2730,15 @@ "url": "pmd_rules_java_design.html#useutilityclass", "summary": "Rules that help you discover design issues." } +, + +{ +"title": "MutableStaticState (Java, Design)", +"tags": "", +"keywords": "MutableStaticState", +"url": "pmd_rules_java_design.html#mutablestaticstate", +"summary": "Rules that help you discover design issues." +}