google / google/error-prone

Feature Request - Check-Then-Act misusage on Java concurrent collections

Open
#2,302 0 comments 0 reactions 0 assignees View on GitHub
Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

### Description of the problem / feature request:

While checking the Check-Then-Act of Java Concurrent Collections famous paper on http://dig.cs.illinois.edu/papers/checkThenAct.pdf , I could not find any implementation of this checker in Errorprone. So, I would like to know that if it is a current need from the community. If so, I could help in developing such a checker.

### Feature requests: what underlying problem are you trying to solve with this feature?

Detect misusage of Check-Then-Act pattern on Java concurrent collections described on http://dig.cs.illinois.edu/papers/checkThenAct.pdf

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Wrong usage:
```
PermissionCollection pc;
chk: if ((pc = loaderPC.get(codeUrl)) == null) {
pc = super.getPermissions(codeSource);
if (pc != null) {
... // initializing "pc"
act: loaderPC.put(codeUrl,pc);
}
}
return (pc);
```
Reasoning:
Suppose that both Thread 1 and Thread 2 execute statement chk and find that the map does not contain the key. Thus, they both calculate the value and put it on the map. Whoever is the last one will overwrite the value put by the other thread. This breaks the put-if-absent semantics of the original code.

### What version of Error Prone are you using?

2.6.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.