harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x..@apache.org
Subject svn commit: r541286 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/WeakHashMap.java test/java/tests/api/java/util/WeakHashMapTest.java
Date Thu, 24 May 2007 12:34:16 GMT
Author: xli
Date: Thu May 24 05:34:15 2007
New Revision: 541286

URL: http://svn.apache.org/viewvc?view=rev&rev=541286
Log:
HARMONY-3883 : [classlib]WeakHashMap.keySet().toArray() intermittently throws NoSuchElementException
in java.lang.ThreadTest of DRLVM kernel test

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java?view=diff&rev=541286&r1=541285&r2=541286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
Thu May 24 05:34:15 2007
@@ -126,7 +126,7 @@
         }
 
         public boolean hasNext() {
-            if (nextEntry != null) {
+            if (nextEntry != null && (nextKey != null || nextEntry.isNull)) {
                 return true;
             }
             while (true) {

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java?view=diff&rev=541286&r1=541285&r2=541286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java
Thu May 24 05:34:15 2007
@@ -297,6 +297,40 @@
 				.size());
 	}
 
+    /**
+     * Regression test for HARMONY-3883
+     * @tests java.util.WeakHashMap#keySet()
+     */
+    public void test_keySet_hasNext() {
+        WeakHashMap map = new WeakHashMap();
+        ConstantHashClass cl = new ConstantHashClass(2);
+        map.put(new ConstantHashClass(1), null);
+        map.put(cl, null);
+        map.put(new ConstantHashClass(3), null);
+        Iterator iter = map.keySet().iterator();
+        iter.next();
+        iter.next();
+        System.gc();
+        assertFalse("Wrong hasNext() value", iter.hasNext());
+    }
+
+    static class ConstantHashClass {
+        private int id = 0;
+
+        public ConstantHashClass(int id) {
+            this.id = id;
+        }
+
+        public int hashCode() {
+            return 0;
+        }
+
+        public String toString() {
+            return "ConstantHashClass[id=" + id + "]";
+        }
+    }
+
+
 	/**
 	 * @tests java.util.WeakHashMap#values()
 	 */



Mime
View raw message