harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Hindess (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-403) HashMap hashcode ignores values in entries
Date Mon, 05 Jun 2006 06:03:30 GMT
    [ http://issues.apache.org/jira/browse/HARMONY-403?page=comments#action_12414698 ] 

Mark Hindess commented on HARMONY-403:
--------------------------------------

Nathan, that test case was a very bad example.  This test is better:

    public void test_hashCode() {
        HashMap map = new HashMap(10);
        Integer key = new Integer(1);
        Integer val = new Integer(2);
        map.put(key, val);
        int expected = key.hashCode() ^ val.hashCode();
        assertEquals(expected, map.hashCode());
        key = new Integer(4);
        val = new Integer(8);
        map.put(key, val);
        expected += key.hashCode() ^ val.hashCode();
        assertEquals(expected, map.hashCode());
    }

Since the hashCode for Integer is defined as:

  a hash code value for this object, equal to the primitive int value 
  represented by this Integer object.

and the hashCode for HashMap (actually from AbstractMap) is:

  This implementation iterates over entrySet(), calling hashCode on
   each element (entry) in the Collection, and adding up the results.

then the hashCode value in the above tests are well-defined for any RI.  This tests fails
on Harmony.


> HashMap hashcode ignores values in entries
> ------------------------------------------
>
>          Key: HARMONY-403
>          URL: http://issues.apache.org/jira/browse/HARMONY-403
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mark Hindess
>     Priority: Minor
>  Attachments: fix.hashmap.hashcode.diff, hashmap.hashcodes.should.differ.diff
>
> While it is obviously trivial to create different HashMaps with identical hashCodes,
I'd still expect the following test code to pass:
>   HashMap map1 = new HashMap(10);
>   HashMap map2 = new HashMap(10);
>   map1.put("key", "1");
>   map2.put("key", "2");
>   assertFalse(map1.hashCode() == map2.hashCode());
> That is, I'd expect the 'value' associated with "key" to have some impact on the hashCode.
 It passes on the reference implementations I tested.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message