Skip to content

Commit aca186b

Browse files
authored
Merge pull request #1294 from yh-semmle/java12-ql
Java: add Java 12 support
2 parents 54091e8 + 3a988d0 commit aca186b

29 files changed

+267
-76
lines changed

java/ql/src/Likely Bugs/Comparison/MissingInstanceofInEquals.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import semmle.code.java.JDK
1717
class CheckedCast extends CastExpr {
1818
CheckedCast() {
1919
exists(TryStmt try, RefType cce |
20-
this.getEnclosingStmt().getParent+() = try and
20+
this.getEnclosingStmt().getEnclosingStmt+() = try and
2121
try.getACatchClause().getVariable().getType() = cce and
2222
cce.getQualifiedName() = "java.lang.ClassCastException"
2323
)

java/ql/src/Likely Bugs/Concurrency/BusyWait.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class DangerStmt extends Stmt {
6969

7070
from WhileStmt s, DangerStmt d
7171
where
72-
d.getParent+() = s and
72+
d.getEnclosingStmt+() = s and
7373
not exists(MethodAccess call | callsCommunicationMethod(call.getMethod()) |
74-
call.getEnclosingStmt().getParent*() = s
74+
call.getEnclosingStmt().getEnclosingStmt*() = s
7575
)
7676
select d, "Prefer wait/notify or java.util.concurrent to communicate between threads."

java/ql/src/Likely Bugs/Concurrency/DoubleCheckedLocking.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
1 = strictcount(FieldAccess fa |
3434
fa.getField() = f and
3535
fa.getEnclosingCallable() = sync.getEnclosingCallable() and
36-
not fa.getEnclosingStmt().getParent*() = sync.getBlock()
36+
not fa.getEnclosingStmt().getEnclosingStmt*() = sync.getBlock()
3737
)
3838
)
3939
select sync, "Double-checked locking on the non-volatile field $@ is not thread-safe.", f,

java/ql/src/Likely Bugs/Concurrency/DoubleCheckedLocking.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ private Expr getANullCheck(Field f) {
3535
* as they are always safe to initialize with double-checked locking.
3636
*/
3737
predicate doubleCheckedLocking(IfStmt if1, IfStmt if2, SynchronizedStmt sync, Field f) {
38-
if1.getThen() = sync.getParent*() and
39-
sync.getBlock() = if2.getParent*() and
38+
if1.getThen() = sync.getEnclosingStmt*() and
39+
sync.getBlock() = if2.getEnclosingStmt*() and
4040
if1.getCondition() = getANullCheck(f) and
4141
if2.getCondition() = getANullCheck(f)
4242
}

java/ql/src/Likely Bugs/Concurrency/DoubleCheckedLockingWithInitRace.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class SideEffect extends Expr {
3434
from IfStmt if1, IfStmt if2, SynchronizedStmt sync, Field f, AssignExpr a, SideEffect se
3535
where
3636
doubleCheckedLocking(if1, if2, sync, f) and
37-
a.getEnclosingStmt().getParent*() = if2.getThen() and
38-
se.getEnclosingStmt().getParent*() = sync.getBlock() and
37+
a.getEnclosingStmt().getEnclosingStmt*() = if2.getThen() and
38+
se.getEnclosingStmt().getEnclosingStmt*() = sync.getBlock() and
3939
a.(ControlFlowNode).getASuccessor+() = se and
4040
a.getDest().(FieldAccess).getField() = f
4141
select a,

java/ql/src/Likely Bugs/Concurrency/FutileSynchOnField.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ from SynchronizedStmt s, Field f, Assignment a
2323
where
2424
synchField(s) = f and
2525
assignmentToField(a) = f and
26-
a.getEnclosingStmt().getParent*() = s
26+
a.getEnclosingStmt().getEnclosingStmt*() = s
2727
select a, "Synchronization on field $@ in futile attempt to guard that field.", f,
2828
f.getDeclaringType().getName() + "." + f.getName()

java/ql/src/Likely Bugs/Concurrency/InconsistentAccess.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ predicate withinInitializer(Expr e) {
2424
}
2525

2626
predicate locallySynchronized(MethodAccess ma) {
27-
ma.getEnclosingStmt().getParent+() instanceof SynchronizedStmt
27+
ma.getEnclosingStmt().getEnclosingStmt+() instanceof SynchronizedStmt
2828
}
2929

3030
predicate hasUnsynchronizedCall(Method m) {
@@ -41,7 +41,7 @@ predicate hasUnsynchronizedCall(Method m) {
4141

4242
predicate withinLocalSynchronization(Expr e) {
4343
e.getEnclosingCallable().isSynchronized() or
44-
e.getEnclosingStmt().getParent+() instanceof SynchronizedStmt
44+
e.getEnclosingStmt().getEnclosingStmt+() instanceof SynchronizedStmt
4545
}
4646

4747
class MyField extends Field {

java/ql/src/Likely Bugs/Concurrency/LazyInitStaticField.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ where
9494
not method instanceof StaticInitializer and
9595
// There must be an unsynchronized read.
9696
exists(IfStmt unsyncNullCheck | unsyncNullCheck = init.getAnEnclosingNullCheck() |
97-
not unsyncNullCheck.getParent+() instanceof ValidSynchStmt
97+
not unsyncNullCheck.getEnclosingStmt+() instanceof ValidSynchStmt
9898
) and
99-
if i.getParent+() instanceof ValidSynchStmt
99+
if i.getEnclosingStmt+() instanceof ValidSynchStmt
100100
then (
101101
not init.getField().isVolatile() and
102102
message = "The field must be volatile."
103103
) else (
104-
if i.getParent+() instanceof SynchronizedStmt
104+
if i.getEnclosingStmt+() instanceof SynchronizedStmt
105105
then message = "Bad synchronization."
106106
else message = "Missing synchronization."
107107
)

java/ql/src/Likely Bugs/Concurrency/SleepWithLock.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
sleep.hasName("sleep") and
2121
sleep.getDeclaringType().hasQualifiedName("java.lang", "Thread") and
2222
(
23-
ma.getEnclosingStmt().getParent*() instanceof SynchronizedStmt or
23+
ma.getEnclosingStmt().getEnclosingStmt*() instanceof SynchronizedStmt or
2424
ma.getEnclosingCallable().isSynchronized()
2525
)
2626
select ma, "sleep() with lock held."

java/ql/src/Likely Bugs/Concurrency/WaitOutsideLoop.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ class WaitMethod extends Method {
2323
from MethodAccess ma
2424
where
2525
ma.getMethod() instanceof WaitMethod and
26-
not exists(LoopStmt s | ma.getEnclosingStmt().getParent*() = s)
26+
not exists(LoopStmt s | ma.getEnclosingStmt().getEnclosingStmt*() = s)
2727
select ma, "To avoid spurious wake-ups, 'wait' should only be called inside a loop."

0 commit comments

Comments
 (0)