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


Version :
Sonarqube: 7.0, SonarJava: 5.6

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.


    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. 


Hi All,

Requesting comments/opinions on this issue.



This seems to me a corner case of using lombok. Before actually going for an adjustement of the engine I would really like to understand how big is the pain for our users. Lombok is a peculiar way to handle java boilerplate code which is not really friendly to static analysis. We already have some mechanism in place to handle some cases specifically for it.

So I don’t think this is worth fixing on our side. You can mark this issue as false positive.