Skip to content

Commit f183a72

Browse files
committed
java: add test for notFullyMonitored
1 parent f4878b3 commit f183a72

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

java/ql/test/query-tests/ThreadSafe/ThreadSafe.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
| examples/LockExample.java:124:5:124:21 | notRelatedToOther | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/LockExample.java:124:5:124:21 | notRelatedToOther | this expression |
3535
| examples/LockExample.java:145:5:145:21 | notRelatedToOther | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/LockExample.java:145:5:145:21 | notRelatedToOther | this expression |
3636
| examples/LockExample.java:153:5:153:21 | notRelatedToOther | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/LockExample.java:153:5:153:21 | notRelatedToOther | this expression |
37+
| examples/ManyLocks.java:8:15:8:15 | y | This field is not properly synchronized in that no single monitor covers all accesses, but the class $@ is annotated as @ThreadSafe. | examples/ManyLocks.java:7:14:7:22 | ManyLocks | ManyLocks |
3738
| examples/SyncLstExample.java:45:5:45:7 | lst | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/SyncLstExample.java:45:5:45:7 | lst | this expression |
3839
| examples/SyncStackExample.java:37:5:37:7 | stc | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/SyncStackExample.java:37:5:37:7 | stc | this expression |
3940
| examples/SynchronizedAndLock.java:10:17:10:22 | length | This field is not properly synchronized in that no single monitor covers all accesses, but the class $@ is annotated as @ThreadSafe. | examples/SynchronizedAndLock.java:7:14:7:32 | SynchronizedAndLock | SynchronizedAndLock |
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package examples;
2+
3+
import java.util.concurrent.locks.Lock;
4+
import java.util.concurrent.locks.ReentrantLock;
5+
6+
@ThreadSafe
7+
public class ManyLocks {
8+
private int y; // $ Alert
9+
10+
private final Lock lock1 = new ReentrantLock();
11+
private final Lock lock2 = new ReentrantLock();
12+
private final Lock lock3 = new ReentrantLock();
13+
14+
public void inc() {
15+
lock1.lock();
16+
lock2.lock();
17+
y++;
18+
lock2.unlock();
19+
lock1.unlock();
20+
}
21+
22+
public void dec() {
23+
lock2.lock();
24+
lock3.lock();
25+
y--;
26+
lock3.unlock();
27+
lock2.unlock();
28+
}
29+
30+
public void reset() {
31+
lock1.lock();
32+
lock3.lock();
33+
y = 0;
34+
lock3.unlock();
35+
lock1.unlock();
36+
}
37+
}

0 commit comments

Comments
 (0)