Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MakeNonReassignedVariablesConstants {
private String varDefinedInClassReassigned = "0"; // Compliant
private String varDefinedInConstructorReassigned = "1"; // Compliant

// using "this"
// using "this"
private String varDefinedInClassNotReassignedByThis = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
private String varDefinedInClassReassignedByThis = "0"; // Compliant
private String varDefinedInConstructorReassignedByThis = "1"; // Compliant
Expand Down Expand Up @@ -45,7 +45,7 @@ public void parameterNotReassigned(final String notReassigned) {
logger.info(notReassigned);
}

public void parameterNotReassignedNotFinal(String notReassigned) { // Noncompliant {{The variable is never reassigned and can be 'final'}}
public void parameterNotReassignedNotFinal(String notReassigned) { // Compliant
logger.info(notReassigned);
}

Expand Down Expand Up @@ -143,7 +143,15 @@ class notReassignedInConstructor{
}
}
class notReassignedInConstructorNotFinal{
notReassignedInConstructorNotFinal(String notReassignedInConstructorNotFinal) { // Noncompliant {{The variable is never reassigned and can be 'final'}}
notReassignedInConstructorNotFinal(String notReassignedInConstructorNotFinal) { // Compliant
System.out.println(notReassignedInConstructorNotFinal);
}
}

interface interfaceMethodWithNullBlockAndBlock <T>{
boolean notNullBlock(T testInterfaceBlock) { // Compliant
logger.info(interfaceWithNullBlock);
}

boolean nullBlock(T testInterfaceNullBlock); // Compliant
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public void visitNode(@Nonnull Tree tree) {
LOGGER.debug(" => isNotReassigned = {}", isNotReassigned(variableTree));
LOGGER.debug(" => isPassedAsNonFinalParameter = {}", isPassedAsNonFinalParameter(variableTree));
}

if(variableTree.symbol().isParameter()){
super.visitNode(tree);
return;
}

if (isNotFinalAndNotStatic(variableTree) && isNotReassigned(variableTree)) {
reportIssue(tree, MESSAGE_RULE);
} else {
Expand Down