Suspicious reference comparison
Opened this issue · 1 comments
scuniff commented
Lines 311 – 315:
final Long previousId = obj.getId();
IObject result = (IObject) filter.filter(null, obj);
result = (IObject) session.merge(result);
final Long currentId = result.getId();
if (previousId != null && previousId != currentId) {
Regarding line 315 and the 2'nd != operator.
I think since previousId and currentId are both Long objects, the != operator compares the object references and not the values. The equals() method should be used.
I think line 315 should be :
if (previousId != null && !previousId.equals(currentId) {
Example snippet:
Long a = (long)1000;
Long b = (long)(999 + 1);
System.out.println("compare != is " + (a!=b));
System.out.println("!equals is " + !a.equals(b));
Output:
compare != is true
!equals is false
False should be the correct output
joshmoore commented
👍