Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8016431

Default implementation of Map.replaceAll fails for CSLM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 8
    • None
    • core-libs

      The default implementation of Map.replaceAll:

          default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
              Objects.requireNonNull(function);
              for (Map.Entry<K, V> entry : entrySet()) {
                  K k;
                  V v;
                  try {
                      k = entry.getKey();
                      v = entry.getValue();
                  } catch(IllegalStateException ise) {
                      throw new ConcurrentModificationException(ise);
                  }
                  entry.setValue(function.apply(k, v));
              }
          }

      fails with UOE on ConcurrentSkipListMap because its entrySet returns immutable map entries. The default should instead do:

          map.put(k, apply(k, v))

      As part of a separate issue, HashMap, TreeMap, LinkedHashMap, ConcurrentHashMap, and ConcurrentSkipListMap should consider overridding Map.replaceAll, because the default is likely to be not as performant.

            mduigou Mike Duigou
            briangoetz Brian Goetz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: