Skip to content

Commit 531b994

Browse files
committed
java: add test for aliasing
found by triage
1 parent 83508ba commit 531b994

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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
@@ -1,3 +1,4 @@
1+
| examples/Alias.java:16:13:16:13 | y | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/Alias.java:16:13:16:13 | y | this expression |
12
| examples/C.java:14:9:14:14 | this.y | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/C.java:14:9:14:14 | this.y | this expression |
23
| examples/C.java:15:9:15:14 | this.y | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/C.java:15:9:15:14 | this.y | this expression |
34
| examples/C.java:16:9:16:14 | this.y | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/C.java:16:9:16:14 | this.y | this expression |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package examples;
2+
3+
import java.util.concurrent.locks.Lock;
4+
import java.util.concurrent.locks.ReentrantLock;
5+
6+
@ThreadSafe
7+
public class Alias {
8+
private int y;
9+
10+
private final ReentrantLock lock = new ReentrantLock();
11+
12+
public void notMismatch() {
13+
final ReentrantLock lock = this.lock;
14+
lock.lock();
15+
try {
16+
y = 42; // $ SPURIOUS: Alert
17+
} finally {
18+
this.lock.unlock();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)