Variable can be made constant.

Why is this an issue ?

Unlike variables, constant values are known at compile time and are injected as is in the code, requiring no runtime processing and therefore reducing the environmental footprint. Although good compilers will const eligible variables by themselves, it is still good practice to declare them constant, as it makes the code intent clearer.

When can it be ignored ?

This rule should not be ignored.

Non compliant examples

public class MyClass {

    private final Logger logger = Logger.getLogger("");

    private Object myNonFinalAndNotReassignedObject = new Object(); // Noncompliant, object initialized but neither used nor reassigned
    private String varDefinedInClassNotReassigned = "0"; // Noncompliant, object initialized and used but not reassigned
    private String varDefinedInClassNotUsed = "0"; // Noncompliant, simple type object initialized but neither used nor reassigned

    void localVariableNotReassigned() {
        String y4 = "10"; // Noncompliant, local variable initialized but not reassigned

        logger.info(y4);
        logger.info(varDefinedInClassNotReassigned);
    }

}

Compliant examples

public class MyClass {

    private final Logger logger = Logger.getLogger(""); // Compliant, object initialized and used (never reassigned but ok because "final" keyword used)

    private Object myNonFinalAndReassignedObject = new Object(); // Compliant, reassigned in method
    private final Object myFinalAndNotReassignedObject = new Object(); // Compliant, object initialized and never reassigned but 'final' keyword used

    private static final String CONSTANT = "toto";  // Compliant, because 'static' and 'final' keywords
    private String varDefinedInClassReassigned = "0"; // Compliant, reassigned in method
    private String varDefinedInConstructorReassigned = "1"; // Compliant, reassigned in constructor

    public MyClass() {
        varDefinedInConstructorReassigned = "3";
        logger.info(varDefinedInConstructorReassigned);
    }

    void localVariableReassigned() {
        String y1 = "10"; // Compliant, reassigned above
        final String PI = "3.14159"; // Compliant, not reassigned but 'final' keyword used

        y1 = "titi";

        logger.info(y1);
        logger.info(PI);
    }

    void localVariableIncrement() {
        String y2 = "10"; // Compliant, reassigned above
        y2 += "titi";
        logger.info(y2);
    }

    void localIntVariableIncrement() {
        int y3 = 10; // Compliant, reassigned above
        ++y3;
        logger.info(y3+"");
    }

    void classVariableReassigned() {
        varDefinedInClassReassigned = "1";

        logger.info(varDefinedInClassReassigned);
        logger.info(varDefinedInClassNotReassigned);
        logger.info(CONSTANT);
    }

    void classVariableReassignedBis() {
        varDefinedInClassReassigned = "2"; // method to avoid sonarqube error asking for moving class variable "varDefinedInClassReassigned" to local variable method
        myNonFinalAndReassignedObject = new Object();

        logger.info(varDefinedInClassReassigned);
        logger.info(myNonFinalAndReassignedObject);
        logger.info(myFinalAndNotReassignedObject);
    }

}