false positive for lombok @EqualsAndHashCode and compareTo

2,294 views
Skip to first unread message

t...@berrycloud.co.uk

unread,
Oct 12, 2015, 8:50:03 AM10/12/15
to SonarQube
Hi

When using the annotations @EqualsAndHashCode, @Value or @Data from Project Lombok, Sonar Java plugin states that equals should be overridden to comply with the contract of compare however equals has already been overridden so I consider this a false positive.

I am using the sonar maven plugin. I am using java plugin version 3.5.

for example:


@Value
@Builder
public class SimpleInstance implements Comparable<SimpleInstance> {






    private final String type;









    @Override
    public int compareTo(SimpleInstance other) {
Override "equals(Object obj)" to comply with the contract of the "compareTo(T o)" method.

sergey4c...@gmail.com

unread,
Oct 29, 2015, 10:39:46 AM10/29/15
to SonarQube, t...@berrycloud.co.uk
True story, I have a related issue with Java plugin version 3.7, assembled from source code (in hope to avoid this problem).


@Data @EqualsAndHashCode(callSuper = true)
public class FeedbackFinalScoreEntity extends IdentityBean{
    private Double finalScore;
    private Integer index;
}

Sonar message:  Override this superclass' "equals" method., SonarQube rule: squid:S2160

понедельник, 12 октября 2015 г., 15:50:03 UTC+3 пользователь t...@berrycloud.co.uk написал:

Nicolas Peru

unread,
Feb 5, 2016, 3:57:37 AM2/5/16
to sergey4c...@gmail.com, SonarQube, t...@berrycloud.co.uk
Hi, 

Sorry for the delay of reply but this will finally be adressed : https://jira.sonarsource.com/browse/SONARJAVA-1513 

Cheers,

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/87afd9e4-4bac-4d9c-b585-f36959720095%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

t...@berrycloud.co.uk

unread,
Feb 5, 2016, 5:32:18 AM2/5/16
to SonarQube, sergey4c...@gmail.com, t...@berrycloud.co.uk
Great thanks for letting me know.  Sonar is a fantastic tool keep up the good work.

t...@nestcottage.co.uk

unread,
Mar 22, 2016, 11:39:16 AM3/22/16
to SonarQube, sergey4c...@gmail.com, t...@berrycloud.co.uk
Hi was this fixed in 3.12?  The above code still seems to be generating false positives. Asides from updating to 3.12 and rerunning the analysis is there anything else I need to do?


On Friday, 5 February 2016 09:57:37 UTC+1, Nicolas Peru wrote:

Michael Gumowski

unread,
Mar 23, 2016, 4:01:20 AM3/23/16
to t...@nestcottage.co.uk, SonarQube, sergey4c...@gmail.com, t...@berrycloud.co.uk
Hello,

The issue has been fixed for version 3.12 of the Java plugin, which should be publicly released pretty soon.
Once released, you will just need to update the java plugin and rerun the analysis to get rid of the issues. However, be sure to provide the bytecode for your analysis.

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

t...@nestcottage.co.uk

unread,
Mar 25, 2016, 1:28:33 PM3/25/16
to SonarQube, t...@nestcottage.co.uk, sergey4c...@gmail.com, t...@berrycloud.co.uk
Hi

I've updated to version 3.12 but it makes no difference.


I have created some tests for https://github.com/SonarSource/sonar-java/blob/master/java-checks/src/test/files/checks/EqualsNotOverridenWithCompareToCheck.java as a pull request, I hope that is helpful (and correct).

Many thanks

Michael Gumowski

unread,
Mar 29, 2016, 3:54:25 AM3/29/16
to Tom Turrell-Croft, SonarQube, Сергей Чернышов, Thomas Turrell-Croft
Hello Tom,

Thank you for the feedback! It seems indeed that in the process we fixed another rule (S2160, see SONARJAVA-1513) that the one which was initially bothering you.
I consequently created the following ticket to fix S1210: SONARJAVA-1614

Regarding your PR, thank you for providing the code samples which should be compliant.
Feel free to expand your PR and provide a fix for the rule! Otherwise, we will handle your PR when handling the ticket.

Cheers,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

Reply all
Reply to author
Forward
0 new messages