Skip to content

Commit d64a936

Browse files
authored
Merge pull request #20088 from aschackmull/java/joinorders1
Java: Improve several join-orders
2 parents f697511 + d9f47bd commit d64a936

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,13 @@ private predicate unificationTargets(RefType t1, Type t2) {
521521
t2 = a2.getComponentType()
522522
)
523523
or
524-
exists(ParameterizedType pt1, ParameterizedType pt2, int pos |
524+
unificationTargetsParameterized(_, _, t1, t2)
525+
}
526+
527+
private predicate unificationTargetsParameterized(
528+
ParameterizedType pt1, ParameterizedType pt2, RefType t1, RefType t2
529+
) {
530+
exists(int pos |
525531
unificationTargets(pt1, pt2) and
526532
t1 = pt1.getTypeArgument(pos) and
527533
t2 = pt2.getTypeArgument(pos)
@@ -565,10 +571,12 @@ private predicate hasParameterSubstitution(
565571
GenericType g1, ParameterizedType pt1, GenericType g2, ParameterizedType pt2, TypeVariable v,
566572
RefType subst
567573
) {
568-
unificationTargets(pt1, pt2) and
569-
exists(int pos | hasSubstitution(pt1.getTypeArgument(pos), pt2.getTypeArgument(pos), v, subst)) and
570-
g1 = pt1.getGenericType() and
571-
g2 = pt2.getGenericType()
574+
exists(RefType t1, RefType t2 |
575+
unificationTargetsParameterized(pt1, pt2, t1, t2) and
576+
hasSubstitution(t1, t2, v, subst) and
577+
g1 = pt1.getGenericType() and
578+
g2 = pt2.getGenericType()
579+
)
572580
}
573581

574582
/**

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,21 @@ private Type erase(Type t) {
12611261
*
12621262
* For the definition of the notion of *erasure* see JLS v8, section 4.6 (Type Erasure).
12631263
*/
1264+
bindingset[t1, t2]
12641265
overlay[caller?]
1265-
pragma[inline]
1266+
pragma[inline_late]
12661267
predicate haveIntersection(RefType t1, RefType t2) {
12671268
exists(RefType e1, RefType e2 | e1 = erase(t1) and e2 = erase(t2) |
1268-
erasedHaveIntersection(e1, e2)
1269+
erasedHaveIntersectionFilter(e1, e2)
12691270
)
12701271
}
12711272

1273+
bindingset[t1, t2]
1274+
pragma[inline_late]
1275+
private predicate erasedHaveIntersectionFilter(RefType t1, RefType t2) {
1276+
erasedHaveIntersection(t1, t2)
1277+
}
1278+
12721279
/**
12731280
* Holds if there is no common (reflexive, transitive) subtype of the erasures
12741281
* of types `t1` and `t2`.

java/ql/src/Likely Bugs/Collections/ContainsTypeMismatch.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class MismatchedContainerAccess extends MethodCall {
103103
|
104104
this.getCallee()
105105
.getDeclaringType()
106-
.getASourceSupertype*()
107106
.getSourceDeclaration()
107+
.getASourceSupertype*()
108108
.hasQualifiedName(package, type) and
109109
this.getCallee().getParameter(i).getType() instanceof TypeObject
110110
)
@@ -119,7 +119,7 @@ class MismatchedContainerAccess extends MethodCall {
119119
containerAccess(package, type, p, this.getCallee().getSignature(), i)
120120
|
121121
t = this.getCallee().getDeclaringType() and
122-
t.getASourceSupertype*().getSourceDeclaration() = g and
122+
t.getSourceDeclaration().getASourceSupertype*() = g and
123123
g.hasQualifiedName(package, type) and
124124
indirectlyInstantiates(t, g, p, result)
125125
)

0 commit comments

Comments
 (0)