Skip to content
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

Suspicious reference comparison #169

Open
scuniff opened this issue Dec 18, 2023 · 1 comment
Open

Suspicious reference comparison #169

scuniff opened this issue Dec 18, 2023 · 1 comment

Comments

@scuniff
Copy link
Contributor

scuniff commented Dec 18, 2023

if (previousId != null && previousId != currentId) {

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
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants