Skip to content

Commit 9c1351c

Browse files
authored
Merge pull request #21149 from aschackmull/java/typeflow-partially-unbound
Java: Add TypeFlow base case for partially unbound types.
2 parents 69de17e + 8b555ca commit 9c1351c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ private module Input implements TypeFlowInput<Location> {
202202
t1e = t2e and
203203
unbound(t2) and
204204
not unbound(t1)
205+
or
206+
t1e = t2e and
207+
exists(int pos |
208+
partiallyUnbound(t2, pos) and
209+
not partiallyUnbound(t1, pos) and
210+
not unbound(t1)
211+
)
205212
)
206213
}
207214

@@ -370,6 +377,11 @@ private module Input implements TypeFlowInput<Location> {
370377
)
371378
}
372379

380+
/** Holds if `t` is a parameterised type with unrestricted type argument at position `pos`. */
381+
private predicate partiallyUnbound(ParameterizedType t, int pos) {
382+
unconstrained(t.getTypeArgument(pos))
383+
}
384+
373385
Type getErasure(Type t) { result = t.getErasure() }
374386

375387
Type getAnAncestor(Type sub) { result = sub.getAnAncestor() }

java/ql/test/library-tests/typeflow/A.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,12 @@ public void m10(Object o) {
118118
default -> { }
119119
}
120120
}
121+
122+
private static <T> T lookupFoo(Map<String, T> m) {
123+
return m.get("foo");
124+
}
125+
126+
public void m11(Map<String, String> m) {
127+
lookupFoo(m);
128+
}
121129
}

java/ql/test/library-tests/typeflow/typeflow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
| A.java:112:23:112:24 | cs | String | false |
1919
| A.java:116:13:116:14 | o2 | String | false |
2020
| A.java:117:49:117:50 | cs | String | false |
21+
| A.java:123:12:123:12 | m | Map<String,String> | false |
2122
| UnionTypes.java:45:7:45:7 | x | Inter | false |
2223
| UnionTypes.java:48:23:48:23 | x | Inter | false |

0 commit comments

Comments
 (0)