@@ -60,13 +60,43 @@ private predicate candidateMethod(RefType t, Method m, string name, int numParam
6060 not whitelist ( name )
6161}
6262
63- pragma [ inline]
64- private predicate potentiallyConfusingTypes ( Type a , Type b ) {
65- exists ( RefType commonSubtype | hasSubtypeOrInstantiation * ( a , commonSubtype ) |
66- hasSubtypeOrInstantiation * ( b , commonSubtype )
63+ predicate paramTypePair ( Type t1 , Type t2 ) {
64+ exists ( Method n , Method m , int i |
65+ overloadedMethodsMostSpecific ( n , m ) and
66+ t1 = n .getParameterType ( i ) and
67+ t2 = m .getParameterType ( i )
6768 )
69+ }
70+
71+ // handle simple cases separately
72+ predicate potentiallyConfusingTypesSimple ( Type t1 , Type t2 ) {
73+ paramTypePair ( t1 , t2 ) and
74+ (
75+ t1 = t2
76+ or
77+ t1 instanceof TypeObject and t2 instanceof RefType
78+ or
79+ t2 instanceof TypeObject and t1 instanceof RefType
80+ or
81+ confusingPrimitiveBoxedTypes ( t1 , t2 )
82+ )
83+ }
84+
85+ // check erased types first
86+ predicate potentiallyConfusingTypesRefTypes ( RefType t1 , RefType t2 ) {
87+ paramTypePair ( t1 , t2 ) and
88+ not potentiallyConfusingTypesSimple ( t1 , t2 ) and
89+ haveIntersection ( t1 , t2 )
90+ }
91+
92+ // then check hasSubtypeOrInstantiation
93+ predicate potentiallyConfusingTypes ( Type t1 , Type t2 ) {
94+ potentiallyConfusingTypesSimple ( t1 , t2 )
6895 or
69- confusingPrimitiveBoxedTypes ( a , b )
96+ potentiallyConfusingTypesRefTypes ( t1 , t2 ) and
97+ exists ( RefType commonSubtype | hasSubtypeOrInstantiation * ( t1 , commonSubtype ) |
98+ hasSubtypeOrInstantiation * ( t2 , commonSubtype )
99+ )
70100}
71101
72102private predicate hasSubtypeOrInstantiation ( RefType t , RefType sub ) {
0 commit comments