Java: Fix bug in qltest and query for immutable types.

This commit is contained in:
Anders Schack-Mulligen
2019-01-18 11:37:38 +01:00
parent 944c082a8d
commit 17b4276699
5 changed files with 33 additions and 13 deletions

View File

@@ -17,6 +17,11 @@ import DoubleCheckedLocking
predicate allFieldsFinal(Class c) { forex(Field f | c.inherits(f) | f.isFinal()) }
predicate immutableFieldType(Type t) {
allFieldsFinal(t) or
t instanceof ImmutableType
}
from IfStmt if1, IfStmt if2, SynchronizedStmt sync, Field f
where
doubleCheckedLocking(if1, if2, sync, f) and
@@ -24,7 +29,7 @@ where
not (
// Non-volatile double-checked locking is ok when the object is immutable and
// there is only a single non-synchronized field read.
allFieldsFinal(f.getType()) and
immutableFieldType(f.getType()) and
1 = strictcount(FieldAccess fa |
fa.getField() = f and
fa.getEnclosingCallable() = sync.getEnclosingCallable() and

View File

@@ -38,6 +38,5 @@ predicate doubleCheckedLocking(IfStmt if1, IfStmt if2, SynchronizedStmt sync, Fi
if1.getThen() = sync.getParent*() and
sync.getBlock() = if2.getParent*() and
if1.getCondition() = getANullCheck(f) and
if2.getCondition() = getANullCheck(f) and
not f.getType() instanceof ImmutableType
if2.getCondition() = getANullCheck(f)
}