Default implementation of Map.replaceAll fails for CSLM

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • 8
    • Affects Version/s: None
    • Component/s: 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.

            Assignee:
            Mike Duigou
            Reporter:
            Brian Goetz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: