Skip to content

[Bug] Incorrect usage of ConcurrentSkipListMap#computeIfAbsent #21301

Closed

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!

Activity

  1. added
    type/bug
    on Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions