src/share/classes/java/util/HashMap.java

Print this page
rev 8056 : 8024331: j.u.Map.computeIfPresent() default/nondefault implementations don't throw NPE if the remappingFunction is null and the key is absent
Summary: Explicitly check for null remappingFunction parameter.
Reviewed-by: TBD
Contributed-by: Brian Burkhalter <brian.burkhalter@oracle.com>

@@ -1130,10 +1130,12 @@
         return v;
     }
 
     public V computeIfPresent(K key,
                               BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
+        if (remappingFunction == null)
+            throw new NullPointerException();
         Node<K,V> e; V oldValue;
         int hash = hash(key);
         if ((e = getNode(hash, key)) != null &&
             (oldValue = e.value) != null) {
             V v = remappingFunction.apply(key, oldValue);