harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Hu (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-4067) [classlib][luni] java.util.Hashtable has a problem with contains
Date Wed, 06 Jun 2007 10:44:26 GMT

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

Robert Hu updated HARMONY-4067:
-------------------------------

    Attachment: HARMONY-4067.diff

Please try this patch.
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
>         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));
> 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.


Mime
View raw message