11private import java
22private import DataFlowPrivate
3+ private import DataFlowUtil
4+ private import semmle.code.java.dataflow.InstanceAccess
35import semmle.code.java.dispatch.VirtualDispatch
46
57private module DispatchImpl {
@@ -17,6 +19,13 @@ private module DispatchImpl {
1719 not p .isVarargs ( ) and
1820 c = ma .getEnclosingCallable ( )
1921 )
22+ or
23+ exists ( OwnInstanceAccess ia |
24+ 2 <= strictcount ( viableImpl ( ma ) ) and
25+ ( ia .isExplicit ( ma .getQualifier ( ) ) or ia .isImplicitMethodQualifier ( ma ) ) and
26+ i = - 1 and
27+ c = ma .getEnclosingCallable ( )
28+ )
2029 }
2130
2231 /**
@@ -37,18 +46,32 @@ private module DispatchImpl {
3746 * relevant call context.
3847 */
3948 private predicate contextArgHasType ( Call ctx , int i , RefType t , boolean exact ) {
40- exists ( Expr arg , Expr src |
41- relevantContext ( ctx , i ) and
42- ctx .getArgument ( i ) = arg and
43- src = variableTrack ( arg ) and
44- exists ( RefType srctype | srctype = src .getType ( ) |
45- exists ( TypeVariable v | v = srctype |
46- t = v .getUpperBoundType + ( ) and not t instanceof TypeVariable
47- )
49+ relevantContext ( ctx , i ) and
50+ exists ( RefType srctype |
51+ exists ( Expr arg , Expr src |
52+ i = - 1 and
53+ ctx .getQualifier ( ) = arg
4854 or
49- t = srctype and not srctype instanceof TypeVariable
50- ) and
51- if src instanceof ClassInstanceExpr then exact = true else exact = false
55+ ctx .getArgument ( i ) = arg
56+ |
57+ src = variableTrack ( arg ) and
58+ srctype = src .getType ( ) and
59+ if src instanceof ClassInstanceExpr then exact = true else exact = false
60+ )
61+ or
62+ exists ( Node arg |
63+ i = - 1 and
64+ not exists ( ctx .getQualifier ( ) ) and
65+ getInstanceArgument ( ctx ) = arg and
66+ arg .getTypeBound ( ) = srctype and
67+ if ctx instanceof ClassInstanceExpr then exact = true else exact = false
68+ )
69+ |
70+ exists ( TypeVariable v | v = srctype |
71+ t = v .getUpperBoundType + ( ) and not t instanceof TypeVariable
72+ )
73+ or
74+ t = srctype and not srctype instanceof TypeVariable
5275 )
5376 }
5477
0 commit comments