Skip to content

Commit ec10b76

Browse files
authored
Merge pull request #1321 from aschackmull/java/polycalls
Approved by pavgust
2 parents 0096024 + 3eb3cd3 commit ec10b76

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Type
88
import Annotation
99
import Exception
1010
import metrics.MetricField
11+
private import dispatch.VirtualDispatch
1112

1213
/**
1314
* A common abstraction for type member declarations,
@@ -115,13 +116,22 @@ class Callable extends StmtParent, Member, @callable {
115116

116117
/**
117118
* Holds if this callable may call the specified callable,
118-
* taking overriding into account.
119+
* taking virtual dispatch into account.
120+
*
121+
* This includes both static call targets and dynamic dispatch targets.
119122
*/
120123
predicate polyCalls(Callable m) {
121-
this.calls(m)
122-
or
123-
exists(Method mSuper, VirtualMethodAccess c | c.getCaller() = this and c.getMethod() = mSuper |
124-
m.(Method).overrides(mSuper)
124+
this.calls(m) or this.callsImpl(m)
125+
}
126+
127+
/**
128+
* Holds if `c` is a viable implementation of a callable called by this
129+
* callable, taking virtual dispatch resolution into account.
130+
*/
131+
predicate callsImpl(Callable c) {
132+
exists(Call call |
133+
call.getCaller() = this and
134+
viableCallable(call) = c
125135
)
126136
}
127137

0 commit comments

Comments
 (0)