You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by xl...@apache.org on 2007/05/24 03:27:47 UTC

svn commit: r541129 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java

Author: xli
Date: Wed May 23 18:27:46 2007
New Revision: 541129

URL: http://svn.apache.org/viewvc?view=rev&rev=541129
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

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=541129&r1=541128&r2=541129
==============================================================================
--- 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 Wed May 23 18:27:46 2007
@@ -178,6 +178,29 @@
                 throw new ConcurrentModificationException();
             }
         }
+
+        /**
+         * Adds next element to the given collection.
+         *
+         * @param coll Collection to add next element to
+         *
+         * @return true if next element exists and was added, false otherwise
+         */
+        private boolean addNext(Collection<R> coll) {
+            if (expectedModCount == modCount) {
+                if (hasNext()) {
+                    currentEntry = nextEntry;
+                    nextEntry = currentEntry.next;
+                    R result = type.get(currentEntry);
+                    // free the key
+                    nextKey = null;
+                    coll.add(result);
+                    return true;
+                }
+                return false;
+            }
+            throw new ConcurrentModificationException();
+        }
     }
 
     /**
@@ -387,20 +410,18 @@
                 @Override
                 public Object[] toArray() {
                     Collection<K> coll = new ArrayList<K>(size());
+                    HashIterator<K> iter = (HashIterator<K>) iterator();
 
-                    for (Iterator<K> iter = iterator(); iter.hasNext();) {
-                        coll.add(iter.next());
-                    }
+                    while(iter.addNext(coll));
                     return coll.toArray();
                 }
 
                 @Override
                 public <T> T[] toArray(T[] contents) {
                     Collection<K> coll = new ArrayList<K>(size());
+                    HashIterator<K> iter = (HashIterator<K>) iterator();
 
-                    for (Iterator<K> iter = iterator(); iter.hasNext();) {
-                        coll.add(iter.next());
-                    }
+                    while(iter.addNext(coll));
                     return coll.toArray(contents);
                 }
             };