Skip to content

Commit c616f57

Browse files
committed
Java: Fix overrides to not be transitive.
1 parent 55ea715 commit c616f57

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The predicate `Method.overrides(Method)` was accidentally transitive. This has been fixed. This fix also affects `Method.overridesOrInstantiates(Method)` and `Method.getASourceOverriddenMethod()`.

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,26 @@ private predicate overrides(Method m1, Method m2) {
289289
)
290290
}
291291

292+
pragma[nomagic]
293+
private predicate overridesCandidateType(RefType tsup, string sig, RefType t, Method m) {
294+
virtualMethodWithSignature(sig, t, m) and
295+
t.extendsOrImplements(tsup)
296+
or
297+
exists(RefType mid |
298+
overridesCandidateType(mid, sig, t, m) and
299+
mid.extendsOrImplements(tsup) and
300+
not virtualMethodWithSignature(sig, mid, _)
301+
)
302+
}
303+
292304
/**
293305
* Auxiliary predicate: whether method `m1` overrides method `m2`,
294306
* ignoring any access modifiers. Additionally, this predicate binds
295307
* `t1` to the type declaring `m1` and `t2` to the type declaring `m2`.
296308
*/
297-
pragma[noopt]
298309
predicate overridesIgnoringAccess(Method m1, RefType t1, Method m2, RefType t2) {
299310
exists(string sig |
300-
virtualMethodWithSignature(sig, t1, m1) and
301-
t1.extendsOrImplements+(t2) and
311+
overridesCandidateType(t2, sig, t1, m1) and
302312
virtualMethodWithSignature(sig, t2, m2)
303313
)
304314
}

0 commit comments

Comments
 (0)