mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
java: add test for notFullyMonitored
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
||||
37
java/ql/test/query-tests/ThreadSafe/examples/ManyLocks.java
Normal file
37
java/ql/test/query-tests/ThreadSafe/examples/ManyLocks.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package examples;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ThreadSafe
|
||||
public class ManyLocks {
|
||||
private int y; // $ Alert
|
||||
|
||||
private final Lock lock1 = new ReentrantLock();
|
||||
private final Lock lock2 = new ReentrantLock();
|
||||
private final Lock lock3 = new ReentrantLock();
|
||||
|
||||
public void inc() {
|
||||
lock1.lock();
|
||||
lock2.lock();
|
||||
y++;
|
||||
lock2.unlock();
|
||||
lock1.unlock();
|
||||
}
|
||||
|
||||
public void dec() {
|
||||
lock2.lock();
|
||||
lock3.lock();
|
||||
y--;
|
||||
lock3.unlock();
|
||||
lock2.unlock();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
lock1.lock();
|
||||
lock3.lock();
|
||||
y = 0;
|
||||
lock3.unlock();
|
||||
lock1.unlock();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user