Skip to content

[Bug] Incorrect usage of ConcurrentSkipListMap#computeIfAbsent #21301

@michaeljmarshall

Description

@michaeljmarshall

Search before asking

  • I searched in the issues and found nothing similar.

Version

master

Minimal reproduce step

ConcurrentSkipListMap#computeIfAbsent does not guarantee only calling the supplier atomically when the value is not present. The following usage appears to be side effecting code that will likely break due to misuse of this method:

entries.computeIfAbsent(key, (k) -> {
size.addAndGet(weighter.getSize(value));
flag.setValue(true);
return value;
});

What did you expect to see?

We need to make sure that we only increment those atomic counters once.

What did you see instead?

There is a chance we'll increment the counters in certain race conditions.

Anything else?

Relevant context can be found here: datastax/cassandra#789 (comment)

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugThe PR fixed a bug or issue reported a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions