Issue
I have a small Java project on Eclipse which I like to check code smells using SonarLint, but today I've got this strange java:S1206
issue which says "equals(Object obj)" and "hashCode()" should be overridden in pairs
.
This issue is being reported on a long-time model object which correctly overrides equals
and hashCode
methods.
I've already tried re-run SonarLint a few times, but the results are the same. Last modification I've done is update some dependencies version and imports.
I'm using Eclipse 2019-12 (4.14.0) Build id: 20191212-1212 and SonarLint for Eclipse version 5.0.0.15138. Eclipse is running using JDK 1.8.0_231.
Project code can be found on my ISS-Tracker GitHub repository.
Solution
Seems like the problem is regarding the Java virtual machine (JVM) version I was using to execute Eclipse. I modified eclipse.ini
file to execute Eclipse using JVM 11 and no issues were reported by SonarLint. To be sure of it, I've removed the configuration, restarted Eclipse, re-executed SonarLint report and the java:S1206 issue reappeared.
For those who are facing the same problem (or similar, perhaps):
Download a Java Virtual Machine 11;
Install the JVM on your machine and annotate (copy) the installation directory (e. g.
/opt/openjdk/jdk-11.0.2
);Open
$ECLIPSE_HOME/eclipse.ini
file on a text editor;Add the following lines replacing
<JAVA_HOME>
by your annotated installation directory;
-vm
<JAVA_HOME>/bin
eclipse.ini
file should be looking like this:
Restart Eclipse.
Run SonarLint report again by right-clicking on project folder, menu
SonarLint
, itemAnalyze
.
Answered By - Marcelo Leite