Skip to content

Suspicious reference comparison #169

Description

@scuniff

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions