mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
java: add test with deeper paths
also format test files
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
| examples/C.java:26:9:26: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:26:9:26:14 | this.y | this expression |
|
||||
| examples/C.java:30:13:30:13 | y | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/C.java:30:13:30:13 | y | this expression |
|
||||
| examples/C.java:33:9:33:9 | y | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/C.java:33:9:33:9 | y | this expression |
|
||||
| examples/DeepPaths.java:8:17:8:17 | y | This field is not properly synchronized in that no single monitor covers all accesses, but the class $@ is annotated as @ThreadSafe. | examples/DeepPaths.java:7:14:7:22 | DeepPaths | DeepPaths |
|
||||
| examples/FaultyTurnstileExample.java:18:5:18:9 | count | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/FaultyTurnstileExample.java:18:5:18:9 | count | this expression |
|
||||
| examples/FaultyTurnstileExample.java:26:15:26:19 | count | This field is not properly synchronized in that no single monitor covers all accesses, but the class $@ is annotated as @ThreadSafe. | examples/FaultyTurnstileExample.java:23:7:23:29 | FaultyTurnstileExample2 | FaultyTurnstileExample2 |
|
||||
| examples/FlawedSemaphore.java:15:14:15:18 | state | This field access (publicly accessible via $@) is not protected by any monitor, but the class is annotated as @ThreadSafe. | examples/FlawedSemaphore.java:15:14:15:18 | state | this expression |
|
||||
@@ -34,7 +35,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/ManyLocks.java:8:17:8:17 | 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 |
|
||||
|
||||
61
java/ql/test/query-tests/ThreadSafe/examples/DeepPaths.java
Normal file
61
java/ql/test/query-tests/ThreadSafe/examples/DeepPaths.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package examples;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ThreadSafe
|
||||
public class DeepPaths {
|
||||
private int y; // $ Alert
|
||||
|
||||
private final Lock lock1 = new ReentrantLock();
|
||||
private final Lock lock2 = new ReentrantLock();
|
||||
private final Lock lock3 = new ReentrantLock();
|
||||
|
||||
public void layer1Locked() {
|
||||
lock1.lock();
|
||||
this.layer2Locked();
|
||||
lock1.unlock();
|
||||
}
|
||||
|
||||
private void layer2Locked() {
|
||||
lock2.lock();
|
||||
this.layer3Unlocked();
|
||||
lock2.unlock();
|
||||
}
|
||||
|
||||
private void layer3Locked() {
|
||||
lock3.lock();
|
||||
y++;
|
||||
lock3.unlock();
|
||||
}
|
||||
|
||||
public void layer1Skip() {
|
||||
lock2.lock();
|
||||
this.layer3Locked();
|
||||
lock2.unlock();
|
||||
}
|
||||
|
||||
public void layer1Indirect() {
|
||||
this.layer2();
|
||||
}
|
||||
|
||||
private void layer2() {
|
||||
this.layer2Locked();
|
||||
}
|
||||
|
||||
public void layer1Unlocked() {
|
||||
this.layer2Unlocked();
|
||||
}
|
||||
|
||||
private void layer2Unlocked() {
|
||||
this.layer3();
|
||||
}
|
||||
|
||||
private void layer3() {
|
||||
this.layer3Locked();
|
||||
}
|
||||
|
||||
private void layer3Unlocked() {
|
||||
y++;
|
||||
}
|
||||
}
|
||||
@@ -5,33 +5,33 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ThreadSafe
|
||||
public class ManyLocks {
|
||||
private int y; // $ Alert
|
||||
private int y; // $ Alert
|
||||
|
||||
private final Lock lock1 = new ReentrantLock();
|
||||
private final Lock lock2 = new ReentrantLock();
|
||||
private final Lock lock3 = new ReentrantLock();
|
||||
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 inc() {
|
||||
lock1.lock();
|
||||
lock2.lock();
|
||||
y++;
|
||||
lock2.unlock();
|
||||
lock1.unlock();
|
||||
}
|
||||
|
||||
public void dec() {
|
||||
lock2.lock();
|
||||
lock3.lock();
|
||||
y--;
|
||||
lock3.unlock();
|
||||
lock2.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();
|
||||
}
|
||||
public void reset() {
|
||||
lock1.lock();
|
||||
lock3.lock();
|
||||
y = 0;
|
||||
lock3.unlock();
|
||||
lock1.unlock();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user