changeset 8791:29731c47f379

better handling of ISE in replaceAll
author mduigou
date Tue, 18 Jun 2013 10:45:24 -0700
parents dc643a58768e
children 649d7fd5dade c7bf11a30ae8
files src/share/classes/java/util/Map.java
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Map.java	Tue Jun 18 11:47:17 2013 -0400
+++ b/src/share/classes/java/util/Map.java	Tue Jun 18 10:45:24 2013 -0700
@@ -579,10 +579,12 @@
     }
 
     /**
-     * Performs the given action on each entry in this map, in the order entries
-     * are returned by an entry set iterator (which may be unspecified), until
-     * all entries have been processed or the action throws an {@code Exception}.
-     * Exceptions thrown by the action are relayed to the caller.
+     * Performs the given action on each entry in this map until all entries
+     * have been processed or the action throws an {@code Exception}.
+     * Exceptions thrown by the action are relayed to the caller. The entries
+     * will be processed in the same order as the entry set iterator unless that
+     * order is unspecified in which case implementations may use an order which
+     * differs from the entry set iterator.
      *
      * <p>The default implementation should be overridden by implementations if
      * they can provide a more performant implementation than an iterator-based
@@ -668,8 +670,16 @@
             try {
                 k = entry.getKey();
                 v = entry.getValue();
+            } catch(IllegalStateException ise) {
+                // this usually means the entry is no longer in the map.
+                throw new ConcurrentModificationException(ise);
+            }
 
-                entry.setValue(function.apply(k, v));
+            // ise thrown from function is not a cme.
+            v = function.apply(k, v);
+
+            try {
+                entry.setValue(v);
             } catch(IllegalStateException ise) {
                 // this usually means the entry is no longer in the map.
                 throw new ConcurrentModificationException(ise);