SonarJava S2159 False Positive: lombok.val variable's equals method invocation

java
scanner
lombok
(Vmurthy) #1

Hi

Version :
Sonarqube: 7.0, SonarJava: 5.6

Description:
The equals method invocation on variable of type lombok.val as shown below incurs a Sonar squid:S2159 which is incorrect. Given lombok’s val is type inferred; this error must be filtered out

Actal Error Message:
Remove this call to “equals”; comparisons between unrelated types always return false.

Snippet:

    import lombok.val;

    class LombokValSillyEqualsIssue {

        public void  s2159OccursForValEquals() {

           val weblabTreatment = getWeblabTreatment(); // Returns a string which is either CONTROL or EXPERIMENT
           if (weblabTreatment.equals("CONTROL")) {
              //...This equals comparison is signalled as S2159 which is incorrect. 
           }

        }
   }
(Vmurthy) #2

Hi All,

Requesting comments/opinions on this issue.

Thanks
Venkat