harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paulex Yang (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-262) java.util.Hashtable, same as HashMap, has similar non-compatible behavior with RI
Date Tue, 28 Mar 2006 06:22:19 GMT
java.util.Hashtable, same as HashMap, has similar non-compatible behavior with RI
---------------------------------------------------------------------------------

         Key: HARMONY-262
         URL: http://issues.apache.org/jira/browse/HARMONY-262
     Project: Harmony
        Type: Bug
  Components: Classlib  
    Reporter: Paulex Yang


Same situation with the prior HashMap issue(http://issues.apache.org/jira/browse/HARMONY-206),
the Hashtable is non-compatible with RI when key is reused with different hash.

Following test case show the non-compatiblity, it passes on RI but fails on Harmony.

public class HashTableTest extends extends junit.framework.TestCase{
        public void test_getLjava_lang_Object() {
		ReusableKey k = new ReusableKey();
		Hashtable h2 = new Hashtable();
		k.setKey(1);
		h2.put(k, "value1");

		k.setKey(13);
		assertNull(h2.get(k));

		k.setKey(12);
		assertNull(h2.get(k));
      }
      static class ReusableKey {
		private int key = 0;

		public void setKey(int key) {
			this.key = key;
		}

		public int hashCode() {
			return key;
		}

		public boolean equals(Object o) {
			if (o == this) {
				return true;
			}
			if (!(o instanceof ReusableKey)) {
				return false;
			}
			return key == ((ReusableKey) o).key;
		}
	}
}

-- 
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