You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Robert Hu (JIRA)" <ji...@apache.org> on 2007/06/07 04:37:27 UTC

[jira] Closed: (HARMONY-4067) [classlib][luni] java.util.Hashtable has a problem with contains

     [ https://issues.apache.org/jira/browse/HARMONY-4067?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Hu closed HARMONY-4067.
------------------------------


Verified.
Thanks a lot!

> [classlib][luni] java.util.Hashtable has a problem with contains
> ----------------------------------------------------------------
>
>                 Key: HARMONY-4067
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4067
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Robert Hu
>            Assignee: Tim Ellison
>         Attachments: HARMONY-4067.diff
>
>
> In  java.util.Hashtable.contains(Object value), there's a tiny bug compared with RI's behavior.
> When we create two object of some special defined classes, A and B, and let :
> A.equals(B) == true but B.equals(A) == false
> This violate the rule of "equals" method, but we can actually create it.
> Then, if we put B into a Hashtable as a value, but not put A, we can find that "contains(B)" returns true but "contains(A)"  returns false.
> Then, if we put A into a Hashtable as a value, but not put B, we can find that "contains(A)" and "contains(B)" all return true.
> But, Harmony does not have this feature.
> Test code snap in a test method:
> class Magic {
> 			private boolean illegal = false;
> 			private String value;
> 			public Magic(boolean illegal,String value) {
> 				super();
> 				this.illegal = illegal;
> 				this.value = value;
> 			}
> 			@Override
> 			public boolean equals(Object obj) {
> 				if(this == obj){
> 					return true;
> 				}
> 				if(! (obj instanceof Magic) || this.value == null){
> 					return false;
> 				}
> 				Magic t = (Magic)obj;
> 				if(t.illegal){
> 					return false;
> 				}
> 				return this.value.equals(t.value);  
> 			}
> 		}
> 		Magic m1 = new Magic(false, "Same");
> 		Magic m2 = new Magic(true, "Same");
> 		assertTrue(m2.equals(m1));
> 		assertFalse(m1.equals(m2));
> 		Hashtable table = new Hashtable();
> 		table.put("key", m1);
> 		assertTrue(table.contains(m1));
> 		assertFalse(table.contains(m2));		
> 		table = new Hashtable();
> 		table.put("key", m2);
> 		assertTrue(table.contains(m1));
> 		assertTrue(table.contains(m2));
> Result:
> RI: Pass
> Harmony: Fail

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.