Skip to content

Inconsistent handling of null values through Java 8 accessors in ConcurrentReferenceHashMap [SPR-16584] #21126

Closed
@spring-projects-issues

Description

@spring-projects-issues

Christoph Strobl opened SPR-16584 and commented

ConcurrentReferenceHashMap needs to override the default implementation of computeIfAbsent in order to allow adding computed null values.

#from: ConcurrentMap.java

... implementation assumes that the ConcurrentMap cannot contain null values and get() returning null unambiguously means the key is absent. Implementations which support null values must override this default implementation.

The following currently fails:

ConcurrentReferenceHashMap<String, Object> map = new ConcurrentReferenceHashMap<>();
map.computeIfAbsent("key", key -> null);

assertThat(map.containsKey("key")).isTrue();

Affects: 4.3.14, 5.0.4

Issue Links:

Referenced from: commits 8d8bb04, 356ef45

Backported to: 4.3.15

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions