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/06 12:42:26 UTC

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

[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


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.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-4067?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison resolved HARMONY-4067.
----------------------------------

    Resolution: Fixed

Thanks Robert.

As you say, if the values are violating the definition of equals then all bets are essentially off.  However, in this case it is a small fix to retain compatibility with the RI so I have no problem committing it.

Patch applied to LUNI module at repo revision r544805.

Please check it was applied as you expected.


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


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-4067?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison reassigned HARMONY-4067:
------------------------------------

    Assignee: Tim Ellison

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


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

Posted by "Robert Hu (JIRA)" <ji...@apache.org>.
     [ 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.


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

Posted by "Robert Hu (JIRA)" <ji...@apache.org>.
     [ 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.


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

Posted by "Robert Hu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-4067?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

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

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


> [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));
> 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.