TreeMap in JDK15 deviates from spec
openjdk at icemanx.nl
Mon Jan 11 19:15:31 UTC 2021
This is a regression, because Java 11 shows "default" twice for the
TreeMap, whereas Java 15 shows "null" twice.
On 11/01/2021 19:05, Phil Smith wrote:
> Hello, I submitted bug report 9068554 recently, but I consider this a
> pretty big issue and I'd like for this not to get lost in triage.
> With JDK-8176894, a specialized implementation for computeIfAbsent was
> added to TreeMap, however it doesn't handle null values correctly.
> Spec states a mapping to null is equivalent to no mapping being
> present, however code will `return t.value;` without checking that
> value. The interface default, for reference, looks like `if ((v =
> get(key)) == null)`.
> A simple repro follows
> TreeMap treemap = new TreeMap();
> treemap.put("a", null);
> System.out.println(treemap.computeIfAbsent("a", key -> "default"));
> HashMap hashmap = new HashMap();
> hashmap.put("a", null);
> System.out.println(hashmap.computeIfAbsent("a", key -> "default"));
More information about the core-libs-dev