Digyter / slim3

Automatically exported from code.google.com/p/slim3
0 stars 0 forks source link

incorrect equals method implementation in ModelRef class #97

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Create a parent Model with a ModelRef.  For example, a Person having an 
Address reference.
2.  Create two instances of Person, p1 and p2 which have the same properties 
and do not have an Address reference assigned.
3. Check if the objects are equal

What is the expected output? What do you see instead?
Expect to see that the objects are the same, i.e. p1.equals(p2) is true
However, p1.equals(p2) is false

What version of the product are you using? On what operating system?
1.0.12

Please provide any additional information below.
I hit this issue when putting an object to the datastore and then getting it 
out again and testing for equality of the parent.

The problem is coming from line 172 of the equals method:

 public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass()) {
            return false;
        }
        Key otherKey = ((ModelRef<?>) obj).getKey();
        if (key == null) {
            return false;
        }
        return key.equals(otherKey);
    }

The logic should not assume that having a null key means that the two objects 
are different. Something along these lines will address this:

 if (key == null) {

            return (otherKey == null);
        }

Original issue reported on code.google.com by turntwo...@gmail.com on 21 Jul 2011 at 6:27

GoogleCodeExporter commented 9 years ago

Original comment by higaya...@gmail.com on 30 Oct 2011 at 4:34