Skip to content

Commit 4f05856

Browse files
jvillardfacebook-github-bot
authored andcommitted
update documentation of ARBITRARY_CODE_EXECUTION_UNDER_LOCK
Summary: Minor improvements to the text as an exercise to improve error messages in general in the future. Reviewed By: ngorogiannis Differential Revision: D31610147 fbshipit-source-id: eda8f916c
1 parent ca617fc commit 4f05856

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
A call which may execute arbitrary code (such as registered, or chained, callbacks) is made while a lock is held.
1+
A call that may execute arbitrary code (such as registered, or chained, callbacks) is made while holding a lock.
22
This code may deadlock whenever the callbacks obtain locks themselves, so it is an unsafe pattern.
3-
This warning is issued only at the innermost lock acquisition around the final call.
43

54
Example:
65
```java
7-
public class NotUnderLock {
86
SettableFuture future = null;
97

10-
public void callFutureSetOk() {
8+
public void callFutureSet() {
119
future.set(null);
1210
}
1311

14-
public synchronized void firstAcquisitionBad() {
15-
callFutureSetOk();
12+
// synchronized means it's taking a lock implicitly
13+
public synchronized void example_of_bad_pattern() {
14+
callFutureSet(); // <- issue reported here
1615
}
1716

18-
public void secondAcquisitionOk(Object o) {
17+
// If the call is made while holding multiple locks, the warning
18+
// will be issued only at the innermost lock acquisition. Here we
19+
// report in example_of_bad_pattern but we won't report below.
20+
public void nested_bad_pattern_no_report(Object o) {
1921
synchronized (o) {
20-
firstAcquisitionBad();
22+
example_of_bad_pattern(); // <- no issue reported
2123
}
2224
}
23-
}
2425
```

website/docs/all-issue-types.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,30 @@ Here is an overview of the issue types currently reported by Infer.
99

1010
Reported as "Arbitrary Code Execution Under lock" by [starvation](/docs/next/checker-starvation).
1111

12-
A call which may execute arbitrary code (such as registered, or chained, callbacks) is made while a lock is held.
12+
A call that may execute arbitrary code (such as registered, or chained, callbacks) is made while holding a lock.
1313
This code may deadlock whenever the callbacks obtain locks themselves, so it is an unsafe pattern.
14-
This warning is issued only at the innermost lock acquisition around the final call.
1514

1615
Example:
1716
```java
18-
public class NotUnderLock {
1917
SettableFuture future = null;
2018

21-
public void callFutureSetOk() {
19+
public void callFutureSet() {
2220
future.set(null);
2321
}
2422

25-
public synchronized void firstAcquisitionBad() {
26-
callFutureSetOk();
23+
// synchronized means it's taking a lock implicitly
24+
public synchronized void example_of_bad_pattern() {
25+
callFutureSet(); // <- issue reported here
2726
}
2827

29-
public void secondAcquisitionOk(Object o) {
28+
// If the call is made while holding multiple locks, the warning
29+
// will be issued only at the innermost lock acquisition. Here we
30+
// report in example_of_bad_pattern but we won't report below.
31+
public void nested_bad_pattern_no_report(Object o) {
3032
synchronized (o) {
31-
firstAcquisitionBad();
33+
example_of_bad_pattern(); // <- no issue reported
3234
}
3335
}
34-
}
3536
```
3637

3738
## ASSIGN_POINTER_WARNING

0 commit comments

Comments
 (0)