You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/09/10 06:11:58 UTC

[GitHub] [ignite-3] zstan commented on a change in pull request #327: review pmd check rules

zstan commented on a change in pull request #327:
URL: https://github.com/apache/ignite-3/pull/327#discussion_r705920281



##########
File path: check-rules/errorprone.xml
##########
@@ -0,0 +1,3721 @@
+<?xml version="1.0"?>
+
+<ruleset name="Error Prone"
+         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
+
+    <description>
+        Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
+    </description>
+
+    <rule name="AssignmentInOperand"
+          language="java"
+          since="1.03"
+          message="Avoid assignments in operands"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AssignmentInOperandRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#assignmentinoperand">
+        <description>
+            Avoid assignments in operands; this can make code more complicated and harder to read.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+public void bar() {
+    int x = 2;
+    if ((x = getX()) == 3) {
+      System.out.println("3!");
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AssignmentToNonFinalStatic"
+          language="java"
+          since="2.2"
+          message="Possible unsafe assignment to a non-final static field in a constructor."
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AssignmentToNonFinalStaticRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#assignmenttononfinalstatic">
+        <description>
+            Identifies a possible unsafe usage of a static field.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+public class StaticField {
+   static int x;
+   public FinalFields(int y) {
+    x = y; // unsafe
+   }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidAccessibilityAlteration"
+          language="java"
+          since="4.1"
+          message="You should not modify visibility of class or methods using getDeclaredConstructors(), getDeclaredConstructor(Class[]), setAccessible() or PrivilegedAction."
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidaccessibilityalteration">
+        <description>
+            Methods such as getDeclaredConstructors(), getDeclaredConstructor(Class[]) and setAccessible(),
+            as the interface PrivilegedAction, allow for the runtime alteration of variable, class, or
+            method visibility, even if they are private. This violates the principle of encapsulation.
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//PrimaryExpression[
+(
+(PrimarySuffix[
+        ends-with(@Image,'getDeclaredConstructors')
+                or
+        ends-with(@Image,'getDeclaredConstructor')
+                or
+        ends-with(@Image,'setAccessible')
+        ])
+or
+(PrimaryPrefix/Name[
+        ends-with(@Image,'getDeclaredConstructor')
+        or
+        ends-with(@Image,'getDeclaredConstructors')
+        or
+        starts-with(@Image,'AccessibleObject.setAccessible')
+        ])
+)
+and
+(//ImportDeclaration/Name[
+        contains(@Image,'java.security.PrivilegedAction')])
+]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+public class Violation {
+  public void invalidCallsInMethod() throws SecurityException, NoSuchMethodException {
+    // Possible call to forbidden getDeclaredConstructors
+    Class[] arrayOfClass = new Class[1];
+    this.getClass().getDeclaredConstructors();
+    this.getClass().getDeclaredConstructor(arrayOfClass);
+    Class clazz = this.getClass();
+    clazz.getDeclaredConstructor(arrayOfClass);
+    clazz.getDeclaredConstructors();
+      // Possible call to forbidden setAccessible
+    clazz.getMethod("", arrayOfClass).setAccessible(false);
+    AccessibleObject.setAccessible(null, false);
+    Method.setAccessible(null, false);
+    Method[] methodsArray = clazz.getMethods();
+    int nbMethod;
+    for ( nbMethod = 0; nbMethod < methodsArray.length; nbMethod++ ) {
+      methodsArray[nbMethod].setAccessible(false);
+    }
+
+      // Possible call to forbidden PrivilegedAction
+    PrivilegedAction priv = (PrivilegedAction) new Object(); priv.run();
+  }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidAssertAsIdentifier"
+          language="java"
+          since="3.4"
+          message="Avoid using assert as an identifier; it became a reserved word in JDK 1.4"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidassertasidentifier">
+        <description>
+            Use of the term 'assert' will conflict with newer versions of Java since it is a reserved word.
+        </description>
+        <priority>2</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>//VariableDeclaratorId[@Name='assert']</value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+public class A {
+    public class Foo {
+        String assert = "foo";
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidBranchingStatementAsLastInLoop"
+          language="java"
+          since="5.0"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidBranchingStatementAsLastInLoopRule"
+          message="Avoid using a branching statement as the last in a loop."
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidbranchingstatementaslastinloop">
+        <description>
+            Using a branching statement as the last part of a loop may be a bug, and/or is confusing.
+            Ensure that the usage is not a bug, or consider using another approach.
+        </description>
+        <priority>2</priority>
+        <example>
+            <![CDATA[
+// unusual use of branching statement in a loop
+for (int i = 0; i < 10; i++) {
+    if (i*i <= 25) {
+        continue;
+    }
+    break;
+}
+
+// this makes more sense...
+for (int i = 0; i < 10; i++) {
+    if (i*i > 25) {
+        break;
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidCallingFinalize"
+          language="java"
+          since="3.0"
+          message="Avoid calling finalize() explicitly"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidCallingFinalizeRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidcallingfinalize">
+        <description>
+            The method Object.finalize() is called by the garbage collector on an object when garbage collection determines
+            that there are no more references to the object. It should not be invoked by application logic.
+
+            Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+void foo() {
+    Bar b = new Bar();
+    b.finalize();
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidCatchingNPE"
+          language="java"
+          since="1.8"
+          message="Avoid catching NullPointerException; consider removing the cause of the NPE."
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidcatchingnpe">
+        <description>
+            Code should never throw NullPointerExceptions under normal circumstances.  A catch block may hide the
+            original error, causing other, more subtle problems later on.
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//CatchStatement/FormalParameter/Type
+ /ReferenceType/ClassOrInterfaceType[@Image='NullPointerException']
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+public class Foo {
+    void bar() {
+        try {
+            // do something
+        } catch (NullPointerException npe) {
+        }
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidCatchingThrowable"
+          language="java"
+          since="1.2"
+          message="A catch statement should never catch throwable since it includes errors."
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidCatchingThrowableRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidcatchingthrowable">
+        <description>
+            Catching Throwable errors is not recommended since its scope is very broad. It includes runtime issues such as
+            OutOfMemoryError that should be exposed and managed separately.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+public void bar() {
+    try {
+        // do something
+    } catch (Throwable th) {  // should not catch Throwable
+        th.printStackTrace();
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidDecimalLiteralsInBigDecimalConstructor"
+          language="java"
+          since="3.4"
+          message="Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoiddecimalliteralsinbigdecimalconstructor">
+        <description>
+            One might assume that the result of "new BigDecimal(0.1)" is exactly equal to 0.1, but it is actually
+            equal to .1000000000000000055511151231257827021181583404541015625.
+            This is because 0.1 cannot be represented exactly as a double (or as a binary fraction of any finite
+            length). Thus, the long value that is being passed in to the constructor is not exactly equal to 0.1,
+            appearances notwithstanding.
+
+            The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal("0.1")' is
+            exactly equal to 0.1, as one would expect.  Therefore, it is generally recommended that the
+            (String) constructor be used in preference to this one.
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//AllocationExpression[pmd-java:typeIs('java.math.BigDecimal')]
+[Arguments/ArgumentList/Expression/PrimaryExpression
+    [
+        pmd-java:typeIs('float') or
+        pmd-java:typeIs('java.lang.Float') or
+        pmd-java:typeIs('double') or
+        pmd-java:typeIs('java.lang.Double')
+    ]
+]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+BigDecimal bd = new BigDecimal(1.123);       // loss of precision, this would trigger the rule
+
+BigDecimal bd = new BigDecimal("1.123");     // preferred approach
+
+BigDecimal bd = new BigDecimal(12);          // preferred approach, ok for integer values
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidDuplicateLiterals"
+          language="java"
+          since="1.0"
+          message="The String literal {0} appears {1} times in this file; the first occurrence is on line {2}"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidDuplicateLiteralsRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidduplicateliterals">
+        <description>
+            Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+private void bar() {
+     buz("Howdy");
+     buz("Howdy");
+     buz("Howdy");
+     buz("Howdy");
+}
+private void buz(String x) {}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidEnumAsIdentifier"
+          language="java"
+          since="3.4"
+          message="Avoid using enum as an identifier; it's a reserved word in JDK 1.5"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidenumasidentifier">
+        <description>
+            Use of the term 'enum' will conflict with newer versions of Java since it is a reserved word.
+        </description>
+        <priority>2</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>//VariableDeclaratorId[@Name='enum']</value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+public class A {
+    public class Foo {
+        String enum = "foo";
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidFieldNameMatchingMethodName"
+          language="java"
+          since="3.0"
+          message="Field {0} has the same name as a method"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidFieldNameMatchingMethodNameRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidfieldnamematchingmethodname">
+        <description>
+            It can be confusing to have a field name with the same name as a method. While this is permitted,
+            having information (field) and actions (method) is not clear naming. Developers versed in
+            Smalltalk often prefer this approach as the methods denote accessor methods.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+public class Foo {
+    Object bar;
+    // bar is data or an action or both?
+    void bar() {
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidFieldNameMatchingTypeName"
+          language="java"
+          since="3.0"
+          message="It is somewhat confusing to have a field name matching the declaring class name"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidFieldNameMatchingTypeNameRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidfieldnamematchingtypename">
+        <description>
+            It is somewhat confusing to have a field name matching the declaring type name.
+            This probably means that type and/or field names should be chosen more carefully.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+public class Foo extends Bar {
+    int foo;    // There is probably a better name that can be used
+}
+public interface Operation {
+    int OPERATION = 1; // There is probably a better name that can be used
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidInstanceofChecksInCatchClause"
+          language="java"
+          since="3.0"
+          message="An instanceof check is being performed on the caught exception.  Create a separate catch clause for this exception type."
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidinstanceofchecksincatchclause">
+        <description>
+            Each caught exception type should be handled in its own catch clause.
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//CatchStatement/FormalParameter
+ /following-sibling::Block//InstanceOfExpression/PrimaryExpression/PrimaryPrefix
+  /Name[
+   @Image = ./ancestor::Block/preceding-sibling::FormalParameter
+    /VariableDeclaratorId/@Name
+  ]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+try { // Avoid this
+    // do something
+} catch (Exception ee) {
+    if (ee instanceof IOException) {
+        cleanup();
+    }
+}
+
+try {  // Prefer this:
+    // do something
+} catch (IOException ee) {
+    cleanup();
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidLiteralsInIfCondition"
+          language="java"
+          since="4.2.6"
+          message="Avoid using Literals in Conditional Statements"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidliteralsinifcondition">
+        <description>
+            Avoid using hard-coded literals in conditional statements. By declaring them as static variables
+            or private members with descriptive names maintainability is enhanced. By default, the literals "-1" and "0" are ignored.
+            More exceptions can be defined with the property "ignoreMagicNumbers".
+
+            The rule doesn't consider deeper expressions by default, but this can be enabled via the property `ignoreExpressions`.
+            With this property set to false, if-conditions like `i == 1 + 5` are reported as well. Note that in that case,
+            the property ignoreMagicNumbers is not taken into account, if there are multiple literals involved in such an expression.
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="ignoreMagicNumbers"
+                      description="Comma-separated list of magic numbers, that should be ignored"
+                      type="String" value="-1,0"/>
+            <property name="ignoreExpressions"
+                      description="If true, only literals in simple if conditions are considered. Otherwise literals in expressions are checked, too."
+                      type="Boolean" value="true"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+(: simple case - no deep expressions :)
+//IfStatement[$ignoreExpressions = true()]/Expression/*/PrimaryExpression/PrimaryPrefix/Literal
+    [not(NullLiteral)]
+    [not(BooleanLiteral)]
+    [empty(index-of(tokenize($ignoreMagicNumbers, '\s*,\s*'), @Image))]
+|
+(: consider also deeper expressions :)
+//IfStatement[$ignoreExpressions = false()]/Expression//*[local-name() != 'UnaryExpression' or @Operator != '-']/PrimaryExpression/PrimaryPrefix/Literal
+    [not(NullLiteral)]
+    [not(BooleanLiteral)]
+    [empty(index-of(tokenize($ignoreMagicNumbers, '\s*,\s*'), @Image))]
+|
+(: consider negative literals :)
+//IfStatement[$ignoreExpressions = false()]/Expression//UnaryExpression[@Operator = '-']/PrimaryExpression/PrimaryPrefix/Literal
+    [not(NullLiteral)]
+    [not(BooleanLiteral)]
+    [empty(index-of(tokenize($ignoreMagicNumbers, '\s*,\s*'), concat('-', @Image)))]
+|
+(: consider multiple literals in expressions :)
+//IfStatement[$ignoreExpressions = false()]/Expression[count(*/PrimaryExpression/PrimaryPrefix/Literal
+    [not(NullLiteral)]
+    [not(BooleanLiteral)]) > 1]
+]]>
+                </value>
+            </property>
+            <property name="version" value="2.0"/>
+        </properties>
+        <example>
+            <![CDATA[
+private static final int MAX_NUMBER_OF_REQUESTS = 10;
+
+public void checkRequests() {
+
+    if (i == 10) {                        // magic number, buried in a method
+      doSomething();
+    }
+
+    if (i == MAX_NUMBER_OF_REQUESTS) {    // preferred approach
+      doSomething();
+    }
+
+    if (aString.indexOf('.') != -1) {}     // magic number -1, by default ignored
+    if (aString.indexOf('.') >= 0) { }     // alternative approach
+
+    if (aDouble > 0.0) {}                  // magic number 0.0
+    if (aDouble >= Double.MIN_VALUE) {}    // preferred approach
+
+    // with rule property "ignoreExpressions" set to "false"
+    if (i == pos + 5) {}  // violation: magic number 5 within an (additive) expression
+    if (i == pos + SUFFIX_LENGTH) {} // preferred approach
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidLosingExceptionInformation"
+          since="4.2.6"
+          language="java"
+          message="Avoid statements in a catch block that invoke accessors on the exception without using the information"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidlosingexceptioninformation">
+        <description>
+            Statements in a catch block that invoke accessors on the exception without using the information
+            only add to code size.  Either remove the invocation, or use the return result.
+        </description>
+        <priority>2</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//CatchStatement/Block/BlockStatement/Statement/StatementExpression/PrimaryExpression/PrimaryPrefix/Name
+[
+   @Image = concat(../../../../../../../FormalParameter/VariableDeclaratorId/@Name, '.getMessage')
+   or
+   @Image = concat(../../../../../../../FormalParameter/VariableDeclaratorId/@Name, '.getLocalizedMessage')
+   or
+   @Image = concat(../../../../../../../FormalParameter/VariableDeclaratorId/@Name, '.getCause')
+   or
+   @Image = concat(../../../../../../../FormalParameter/VariableDeclaratorId/@Name, '.getStackTrace')
+   or
+   @Image = concat(../../../../../../../FormalParameter/VariableDeclaratorId/@Name, '.toString')
+]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+public void bar() {
+    try {
+        // do something
+    } catch (SomeException se) {
+        se.getMessage();
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidMultipleUnaryOperators"
+          language="java"
+          since="4.2"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidMultipleUnaryOperatorsRule"
+          message="Using multiple unary operators may be a bug, and/or is confusing."
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidmultipleunaryoperators">
+        <description>
+            The use of multiple unary operators may be problematic, and/or confusing.
+            Ensure that the intended usage is not a bug, or consider simplifying the expression.
+        </description>
+        <priority>2</priority>
+        <example>
+            <![CDATA[
+// These are typo bugs, or at best needlessly complex and confusing:
+int i = - -1;
+int j = + - +1;
+int z = ~~2;
+boolean b = !!true;
+boolean c = !!!true;
+
+// These are better:
+int i = 1;
+int j = -1;
+int z = 2;
+boolean b = true;
+boolean c = false;
+
+// And these just make your brain hurt:
+int i = ~-2;
+int j = -~7;
+]]>
+        </example>
+    </rule>
+
+    <rule name="AvoidUsingOctalValues"
+          language="java"
+          since="3.9"
+          message="Do not start a literal by 0 unless it's an octal value"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.AvoidUsingOctalValuesRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidusingoctalvalues">
+        <description>
+            Integer literals should not start with zero since this denotes that the rest of literal will be
+            interpreted as an octal value.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+int i = 012;    // set i with 10 not 12
+int j = 010;    // set j with 8 not 10
+k = i * j;      // set k with 80 not 120
+]]>
+        </example>
+    </rule>
+
+    <rule name="BadComparison" ref="ComparisonWithNaN" deprecated="true" />
+
+    <rule name="BeanMembersShouldSerialize"
+          language="java"
+          since="1.1"
+          message="Found non-transient, non-static member. Please mark as transient or provide accessors."
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.BeanMembersShouldSerializeRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#beanmembersshouldserialize">
+        <description>
+            If a class is a bean, or is referenced by a bean directly or indirectly it needs to be serializable.
+            Member variables need to be marked as transient, static, or have accessor methods in the class. Marking
+            variables as transient is the safest and easiest modification. Accessor methods should follow the Java
+            naming conventions, i.e. for a variable named foo, getFoo() and setFoo() accessor methods should be provided.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+private transient int someFoo;  // good, it's transient
+private static int otherFoo;    // also OK
+private int moreFoo;            // OK, has proper accessors, see below
+private int badFoo;             // bad, should be marked transient
+
+private void setMoreFoo(int moreFoo){
+      this.moreFoo = moreFoo;
+}
+
+private int getMoreFoo(){
+      return this.moreFoo;
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="BrokenNullCheck"
+          language="java"
+          since="3.8"
+          message="Method call on object which may be null"
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.BrokenNullCheckRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#brokennullcheck">
+        <description>
+            The null check is broken since it will throw a NullPointerException itself.
+            It is likely that you used || instead of &amp;&amp; or vice versa.
+        </description>
+        <priority>2</priority>
+        <example>
+            <![CDATA[
+public String bar(String string) {
+  // should be &&
+    if (string!=null || !string.equals(""))
+        return string;
+  // should be ||
+    if (string==null && string.equals(""))
+        return string;
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="CallSuperFirst"
+          since="4.2.5"
+          language="java"
+          message="super should be called at the start of the method"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#callsuperfirst">
+        <description>Super should be called at the start of the method</description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//MethodDeclaration[
+  @Name='onCreate' or
+  @Name='onConfigurationChanged' or
+  @Name='onPostCreate' or
+  @Name='onPostResume' or
+  @Name='onRestart' or
+  @Name='onRestoreInstanceState' or
+  @Name='onResume' or
+  @Name='onStart'
+  ]
+    /Block[not(
+      (BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier= true()]]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name]))]
+[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
+  pmd-java:typeIs('android.app.Activity') or
+  pmd-java:typeIs('android.app.Application') or
+  pmd-java:typeIs('android.app.Service')
+]]]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+public class DummyActivity extends Activity {
+    public void onCreate(Bundle bundle) {
+        // missing call to super.onCreate(bundle)
+        foo();
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="CallSuperLast"
+          since="4.2.5"
+          language="java"
+          message="super should be called at the end of the method"
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#callsuperlast">
+        <description>
+            Super should be called at the end of the method
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//MethodDeclaration[
+  @Name='finish' or
+  @Name='onDestroy' or
+  @Name='onPause' or
+  @Name='onSaveInstanceState' or
+  @Name='onStop' or
+  @Name='onTerminate'
+  ]
+   /Block/BlockStatement[last()]
+    [not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier= true()]]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name])]
+[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
+  pmd-java:typeIs('android.app.Activity') or
+  pmd-java:typeIs('android.app.Application') or
+  pmd-java:typeIs('android.app.Service')
+]]]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+public class DummyActivity extends Activity {
+    public void onPause() {
+        foo();
+        // missing call to super.onPause()
+    }
+}
+]]>
+        </example>
+    </rule>
+
+    <rule name="CheckSkipResult"
+          language="java"
+          since="5.0"
+          message="Check the value returned by the skip() method of an InputStream to see if the requested number of bytes has been skipped."
+          class="net.sourceforge.pmd.lang.java.rule.errorprone.CheckSkipResultRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#checkskipresult">
+        <description>
+            The skip() method may skip a smaller number of bytes than requested. Check the returned value to find out if it was the case or not.
+        </description>
+        <priority>3</priority>
+        <example>
+            <![CDATA[
+public class Foo {
+
+   private FileInputStream _s = new FileInputStream("file");
+
+   public void skip(int n) throws IOException {
+      _s.skip(n); // You are not sure that exactly n bytes are skipped
+   }
+
+   public void skipExactly(int n) throws IOException {
+      while (n != 0) {
+         long skipped = _s.skip(n);
+         if (skipped == 0)
+            throw new EOFException();
+         n -= skipped;
+      }
+   }
+]]>
+        </example>
+    </rule>
+
+    <rule name="ClassCastExceptionWithToArray"
+          language="java"
+          since="3.4"
+          message="This usage of the Collection.toArray() method will throw a ClassCastException."
+          class="net.sourceforge.pmd.lang.rule.XPathRule"
+          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#classcastexceptionwithtoarray">
+        <description>
+            When deriving an array of a specific class from your Collection, one should provide an array of
+            the same class as the parameter of the toArray() method. Doing otherwise you will will result
+            in a ClassCastException.
+        </description>
+        <priority>3</priority>
+        <properties>
+            <property name="version" value="2.0"/>
+            <property name="xpath">
+                <value>
+                    <![CDATA[
+//CastExpression[Type/ReferenceType/ClassOrInterfaceType[@Image != "Object"]]
+    /PrimaryExpression
+    [PrimaryPrefix/Name[ends-with(@Image, '.toArray')]]
+    [PrimarySuffix/Arguments[not(*)]]
+    [count(PrimarySuffix) = 1]
+]]>
+                </value>
+            </property>
+        </properties>
+        <example>
+            <![CDATA[
+Collection c = new ArrayList();
+Integer obj = new Integer(1);
+c.add(obj);
+
+    // this would trigger the rule (and throw a ClassCastException if executed)
+Integer[] a = (Integer [])c.toArray();
+
+   // this is fine and will not trigger the rule
+Integer[] b = (Integer [])c.toArray(new Integer[c.size()]);
+]]>
+        </example>
+    </rule>
+
+    <rule name="CloneMethodMustBePublic"

Review comment:
       I stopped here, seems all upper is appropriate and very helpful.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org