diff --git a/java-checks-test-sources/default/src/main/java/checks/SelfAssignementCheck.java b/java-checks-test-sources/default/src/main/java/checks/SelfAssignementCheck.java index a57d410dc18..6b1faefcd25 100644 --- a/java-checks-test-sources/default/src/main/java/checks/SelfAssignementCheck.java +++ b/java-checks-test-sources/default/src/main/java/checks/SelfAssignementCheck.java @@ -1,6 +1,12 @@ package checks; class SelfAssignementCheck { + static int staticField = 0; + + static { + staticField = staticField; // Noncompliant + } + int a, c = 0; int[] b = {0}; diff --git a/java-checks/src/main/java/org/sonar/java/checks/SelfAssignementCheck.java b/java-checks/src/main/java/org/sonar/java/checks/SelfAssignementCheck.java index fb13811f72b..712065145cf 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/SelfAssignementCheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/SelfAssignementCheck.java @@ -90,7 +90,7 @@ private static JavaQuickFix getQuickFix(AssignmentExpressionTree tree) { MethodTree methodParent = (MethodTree) ExpressionUtils.getParentOfType(tree, Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR); String name = getName(tree.variable()); - boolean isMethodParameter = methodParent.parameters().stream() + boolean isMethodParameter = methodParent != null && methodParent.parameters().stream() .map(p -> p.simpleName().name()) .anyMatch(p -> p.equals(name));