You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/07/03 22:47:39 UTC

svn commit: r418844 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/java/tests/api/java/util/HashMapTest.java

Author: ndbeyer
Date: Mon Jul  3 13:47:39 2006
New Revision: 418844

URL: http://svn.apache.org/viewvc?rev=418844&view=rev
Log:
Apply patch and additional fixes for HARMONY-403: HashMap hashcode ignores values in entries

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java?rev=418844&r1=418843&r2=418844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java Mon Jul  3 13:47:39 2006
@@ -47,7 +47,8 @@
 
         Entry(K theKey, V theValue) {
             super(theKey, theValue);
-            this.hash = (theKey == null) ? 0 : theKey.hashCode();
+            this.hash = (theKey == null ? 0 : theKey.hashCode())
+                    ^ (theValue == null ? 0 : theValue.hashCode());
         }
 
         @Override
@@ -523,8 +524,11 @@
                 index = key == null ? 0 : (key.hashCode() & 0x7FFFFFFF)
                         % elementData.length;
             }
-            entry = createEntry(key, index, null);
+            entry = createEntry(key, index, value);
+            //new entry, so nothing is replaced
+            return null;
         }
+        
         V result = entry.value;
         entry.value = value;
         return result;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java?rev=418844&r1=418843&r2=418844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java Mon Jul  3 13:47:39 2006
@@ -409,6 +409,20 @@
 			return key == ((ReusableKey) o).key;
 		}
 	}
+    
+    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());
+    } 
 	
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



RE: svn commit: r418844 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/java/tests/api/java/util/HashMapTest.java

Posted by Nathan Beyer <nb...@kc.rr.com>.
Sorry about that. I've applied a new fix that resolves this and my Windows
build/test is working. It seems that
http://issues.apache.org/jira/browse/HARMONY-403 was actually caused by the
changes made for http://issues.apache.org/jira/browse/HARMONY-206. 

> -----Original Message-----
> From: Tim Ellison [mailto:t.p.ellison@gmail.com]
> Sent: Tuesday, July 04, 2006 4:35 AM
> To: harmony-dev@incubator.apache.org
> Subject: Re: svn commit: r418844 - in
> /incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
> main/java/java/util/HashMap.java
> test/java/tests/api/java/util/HashMapTest.java
> 
> Nathan,
> 
> I have rolled back this commit (in r418963) because it was causing lots
> of test failures on Linux and Windows.
> 
> Please can you take another look at it?
> 
> Regards,
> Tim
> 
> 
> ndbeyer@apache.org wrote:
> > Author: ndbeyer
> > Date: Mon Jul  3 13:47:39 2006
> > New Revision: 418844
> >
> > URL: http://svn.apache.org/viewvc?rev=418844&view=rev
> > Log:
> > Apply patch and additional fixes for HARMONY-403: HashMap hashcode
> ignores values in entries
> >
> > Modified:
> >
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/
> util/HashMap.java
> >
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests
> /api/java/util/HashMapTest.java
> >
> > Modified:
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/
> util/HashMap.java
> > URL:
> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/mod
> ules/luni/src/main/java/java/util/HashMap.java?rev=418844&r1=418843&r2=418
> 844&view=diff
> >
> ==========================================================================
> ====
> > ---
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/
> util/HashMap.java (original)
> > +++
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/
> util/HashMap.java Mon Jul  3 13:47:39 2006
> > @@ -47,7 +47,8 @@
> >
> >          Entry(K theKey, V theValue) {
> >              super(theKey, theValue);
> > -            this.hash = (theKey == null) ? 0 : theKey.hashCode();
> > +            this.hash = (theKey == null ? 0 : theKey.hashCode())
> > +                    ^ (theValue == null ? 0 : theValue.hashCode());
> >          }
> >
> >          @Override
> > @@ -523,8 +524,11 @@
> >                  index = key == null ? 0 : (key.hashCode() & 0x7FFFFFFF)
> >                          % elementData.length;
> >              }
> > -            entry = createEntry(key, index, null);
> > +            entry = createEntry(key, index, value);
> > +            //new entry, so nothing is replaced
> > +            return null;
> >          }
> > +
> >          V result = entry.value;
> >          entry.value = value;
> >          return result;
> >
> > Modified:
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests
> /api/java/util/HashMapTest.java
> > URL:
> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/mod
> ules/luni/src/test/java/tests/api/java/util/HashMapTest.java?rev=418844&r1
> =418843&r2=418844&view=diff
> >
> ==========================================================================
> ====
> > ---
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests
> /api/java/util/HashMapTest.java (original)
> > +++
> incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests
> /api/java/util/HashMapTest.java Mon Jul  3 13:47:39 2006
> > @@ -409,6 +409,20 @@
> >  			return key == ((ReusableKey) o).key;
> >  		}
> >  	}
> > +
> > +    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());
> > +    }
> >
> >  	/**
> >  	 * Sets up the fixture, for example, open a network connection. This
> method
> >
> >
> >
> 
> --
> 
> Tim Ellison (t.p.ellison@gmail.com)
> IBM Java technology centre, UK.
> 
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: svn commit: r418844 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/java/tests/api/java/util/HashMapTest.java

Posted by Tim Ellison <t....@gmail.com>.
Nathan,

I have rolled back this commit (in r418963) because it was causing lots
of test failures on Linux and Windows.

Please can you take another look at it?

Regards,
Tim


ndbeyer@apache.org wrote:
> Author: ndbeyer
> Date: Mon Jul  3 13:47:39 2006
> New Revision: 418844
> 
> URL: http://svn.apache.org/viewvc?rev=418844&view=rev
> Log:
> Apply patch and additional fixes for HARMONY-403: HashMap hashcode ignores values in entries
> 
> Modified:
>     incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
>     incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
> 
> Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
> URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java?rev=418844&r1=418843&r2=418844&view=diff
> ==============================================================================
> --- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java (original)
> +++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java Mon Jul  3 13:47:39 2006
> @@ -47,7 +47,8 @@
>  
>          Entry(K theKey, V theValue) {
>              super(theKey, theValue);
> -            this.hash = (theKey == null) ? 0 : theKey.hashCode();
> +            this.hash = (theKey == null ? 0 : theKey.hashCode())
> +                    ^ (theValue == null ? 0 : theValue.hashCode());
>          }
>  
>          @Override
> @@ -523,8 +524,11 @@
>                  index = key == null ? 0 : (key.hashCode() & 0x7FFFFFFF)
>                          % elementData.length;
>              }
> -            entry = createEntry(key, index, null);
> +            entry = createEntry(key, index, value);
> +            //new entry, so nothing is replaced
> +            return null;
>          }
> +        
>          V result = entry.value;
>          entry.value = value;
>          return result;
> 
> Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
> URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java?rev=418844&r1=418843&r2=418844&view=diff
> ==============================================================================
> --- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java (original)
> +++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java Mon Jul  3 13:47:39 2006
> @@ -409,6 +409,20 @@
>  			return key == ((ReusableKey) o).key;
>  		}
>  	}
> +    
> +    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());
> +    } 
>  	
>  	/**
>  	 * Sets up the fixture, for example, open a network connection. This method
> 
> 
> 

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org