Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Request: AvoidNonAtomicIfPutOnConcurrentMap #534

Open
jborgers opened this issue Feb 11, 2025 · 1 comment
Open

Rule Request: AvoidNonAtomicIfPutOnConcurrentMap #534

jborgers opened this issue Feb 11, 2025 · 1 comment

Comments

@jborgers
Copy link
Owner

Check-Modify constructs are the most subtle and most occurring concurrency bugs. When using a ConcurrentMap, it is a multi-threading environment, so separate check and modify is a concurrency bug.

Example:

void foo(ConcurrentMap<String, Account> accountMap, String accKey) {
     if(!accountMap.containsKey(accKey)){
            accountMap.put(accKey, account);
      }
}

accountMap.putIfAbsent(accKey, account) should be used

@jborgers jborgers changed the title Rule Request: Avoid Rule Request: AvoidNonAtomicIfPutOnConcurrentMap Feb 11, 2025
@jborgers
Copy link
Owner Author

Note it needs support for local var (used in parallelStream), formal param and field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant