-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SonarQube bugs #1060
SonarQube bugs #1060
Conversation
@aalhossary Can you please review this PR |
I think auto-unboxing takes care of this in most cases. For instance if I rewrite your first test as: Integer m = 1;
Integer n = 1;
System.out.println(m==n); The output is |
Interestingly this doesn't work: Integer m = new Integer(1);
Integer n = new Integer(1);
System.out.println(m==n); but this works: Integer m = Integer.valueOf(1);
Integer n = Integer.valueOf(1);
System.out.println(m==n); |
@josemduarte That is because of the internal implementation of Therefore, checking the equality of two autoboxed wrappers using However, the situation in this pull request (and the previous one) is actually about "not equal". |
comparison rather than equality comparison. When using the "not equal" operator (!=) to compare two autoboxed Integer values, the result is not guaranteed to be correct, even within the range you mentioned. This is because the "not equal" operator first unboxes the Integer values into primitive int values and then compares those values. If the two Integer values being compared happen to be in the cached range, they will be the same object reference and thus have the same primitive value. However, if they are not in the cached range, they will be different object references even if they have the same primitive value, and the "not equal" comparison will return false when it should have returned true. To avoid this issue, it's recommended to use the equals() method for comparing two autoboxed Integer values instead of the "not equal" operator, as it compares the values of the objects rather than their references. |
@aalhossary See the implementation on Objects.equals(); It first compares the objects with == operator. I hope using equals method safe. public static boolean equals(Object a, Object b) { |
@aalhossary |
@tmrpavan using |
@josemduarte Now both this PR and #1052 address the same issue (i.e. duplicates). |
@aalhossary Any update on this |
Since #1052 has gone quiet (specially from the PR creator side). Let's close that one in favour of this. Still we'll want to review this PR of course. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments on your modifications
biojava-genome/src/main/java/org/biojava/nbio/genome/homology/GFF3FromUniprotBlastHits.java
Outdated
Show resolved
Hide resolved
biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java
Outdated
Show resolved
Hide resolved
biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/core/RotationSolver.java
Outdated
Show resolved
Hide resolved
biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/core/SystematicSolver.java
Outdated
Show resolved
Hide resolved
I am working on this |
@aalhossary Modified as per the comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
Avoid Comparing Integers in Java using == Operator