8259622: TreeMap.computeIfAbsent deviates from spec

Reviewed-by: smarks
This commit is contained in:
Tagir F. Valeev 2021-01-15 04:11:31 +00:00
parent d701babb06
commit 2c8e337dff
2 changed files with 26 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -575,8 +575,12 @@ public class TreeMap<K,V>
t = t.left;
else if (cmp > 0)
t = t.right;
else
else {
if (t.value == null) {
t.value = callMappingFunctionWithCheck(key, mappingFunction);
}
return t.value;
}
} while (t != null);
} else {
Objects.requireNonNull(key);
@ -589,8 +593,12 @@ public class TreeMap<K,V>
t = t.left;
else if (cmp > 0)
t = t.right;
else
else {
if (t.value == null) {
t.value = callMappingFunctionWithCheck(key, mappingFunction);
}
return t.value;
}
} while (t != null);
}
newValue = callMappingFunctionWithCheck(key, mappingFunction);