Skip to content

Commit c149754

Browse files
committed
Fix java/iterator-remove-failure to handle calls to specialised generic functions
1 parent 3bdccb3 commit c149754

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ predicate containsSpecialCollection(Expr e, SpecialCollectionCreation origin) {
3636
or
3737
exists(Call c, int i |
3838
containsSpecialCollection(c.getArgument(i), origin) and
39-
e = c.getCallee().getParameter(i).getAnAccess()
39+
e = c.getCallee().getSourceDeclaration().getParameter(i).getAnAccess()
4040
)
4141
or
4242
exists(Call c, ReturnStmt r | e = c |
43-
r.getEnclosingCallable() = c.getCallee() and
43+
r.getEnclosingCallable() = c.getCallee().getSourceDeclaration() and
4444
containsSpecialCollection(r.getResult(), origin)
4545
)
4646
}
@@ -58,11 +58,11 @@ predicate iterOfSpecialCollection(Expr e, SpecialCollectionCreation origin) {
5858
or
5959
exists(Call c, int i |
6060
iterOfSpecialCollection(c.getArgument(i), origin) and
61-
e = c.getCallee().getParameter(i).getAnAccess()
61+
e = c.getCallee().getSourceDeclaration().getParameter(i).getAnAccess()
6262
)
6363
or
6464
exists(Call c, ReturnStmt r | e = c |
65-
r.getEnclosingCallable() = c.getCallee() and
65+
r.getEnclosingCallable() = c.getCallee().getSourceDeclaration() and
6666
iterOfSpecialCollection(r.getResult(), origin)
6767
)
6868
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| Test.java:16:5:16:17 | remove(...) | This call may fail when iterating over the collection created $@, since it does not support element removal. | Test.java:29:16:29:32 | asList(...) | here |
22
| Test.java:16:5:16:17 | remove(...) | This call may fail when iterating over the collection created $@, since it does not support element removal. | Test.java:33:16:33:43 | singletonList(...) | here |
3+
| Test.java:44:3:44:23 | remove(...) | This call may fail when iterating over the collection created $@, since it does not support element removal. | Test.java:52:15:52:31 | asList(...) | here |

java/ql/test/query-tests/IteratorRemoveMayFail/Test.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,20 @@ public static A mkA2(int i) {
3636
public List<Integer> getL() {
3737
return l;
3838
}
39+
}
40+
41+
class Parent<T> {
42+
43+
public void removeFirst(List<T> l) {
44+
l.iterator().remove();
45+
}
46+
47+
}
48+
49+
class Child extends Parent<String> {
50+
51+
public void test(String... ss) {
52+
removeFirst(Arrays.asList(ss));
53+
}
54+
3955
}

0 commit comments

Comments
 (0)