-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
8, 9, 10
A DESCRIPTION OF THE REQUEST :
SingletonMap have single mapping and should check for existing key before throw exception:
@Override
public V computeIfAbsent(K key,
Function<? super K, ? extends V> mappingFunction) {
if (eq(key, k))
return v;
throw new UnsupportedOperationException();
}
Default method from java.util.Map works as expected except mapping function was called.
JUSTIFICATION :
Changes in underlying framework which starts using computeIfAbsent cause code changes to avoid SingletonMap
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
method return value
ACTUAL -
java.lang.UnsupportedOperationException thrown
---------- BEGIN SOURCE ----------
java.util.Collections.singletonMap("k", "v").computeIfAbsent("k", k -> "v" );
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use another Map implementation
SingletonMap have single mapping and should check for existing key before throw exception:
@Override
public V computeIfAbsent(K key,
Function<? super K, ? extends V> mappingFunction) {
if (eq(key, k))
return v;
throw new UnsupportedOperationException();
}
Default method from java.util.Map works as expected except mapping function was called.
JUSTIFICATION :
Changes in underlying framework which starts using computeIfAbsent cause code changes to avoid SingletonMap
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
method return value
ACTUAL -
java.lang.UnsupportedOperationException thrown
---------- BEGIN SOURCE ----------
java.util.Collections.singletonMap("k", "v").computeIfAbsent("k", k -> "v" );
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use another Map implementation