prashant18691 / deep-equals

Automatically exported from code.google.com/p/deep-equals
0 stars 0 forks source link

Wrong hashCode when multiple booleans are involved #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This test case should pass, but it currently fails:

public void testBoolean (){
        Booleans booleans1 = new Booleans();
        booleans1.value1 = false;
        booleans1.value2 = true;
        booleans1.value3 = false;

        Booleans booleans2 = new Booleans();
        booleans2.value1 = false;
        booleans2.value2 = true;
        booleans2.value3 = true;
        assertNotEquals(DeepEquals.deepHashCode(booleans1), DeepEquals.deepHashCode(booleans2));
    }

    private class Booleans {
        boolean value1;
        boolean value2;
        boolean value3;
    }

The problem is the contains-check, which always returns _true_ once 
Boolean.FALSE and Boolean.TRUE have been visited:

if (obj == null || visited.contains(obj)) {
   continue;
}

Using IdentityHashMap might help in this scenario.

Original issue reported on code.google.com by etienne....@edorasware.com on 11 Jun 2014 at 11:25