mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Fix java/iterator-remove-failure to handle calls to specialised generic functions
This commit is contained in:
@@ -36,11 +36,11 @@ predicate containsSpecialCollection(Expr e, SpecialCollectionCreation origin) {
|
||||
or
|
||||
exists(Call c, int i |
|
||||
containsSpecialCollection(c.getArgument(i), origin) and
|
||||
e = c.getCallee().getParameter(i).getAnAccess()
|
||||
e = c.getCallee().getSourceDeclaration().getParameter(i).getAnAccess()
|
||||
)
|
||||
or
|
||||
exists(Call c, ReturnStmt r | e = c |
|
||||
r.getEnclosingCallable() = c.getCallee() and
|
||||
r.getEnclosingCallable() = c.getCallee().getSourceDeclaration() and
|
||||
containsSpecialCollection(r.getResult(), origin)
|
||||
)
|
||||
}
|
||||
@@ -58,11 +58,11 @@ predicate iterOfSpecialCollection(Expr e, SpecialCollectionCreation origin) {
|
||||
or
|
||||
exists(Call c, int i |
|
||||
iterOfSpecialCollection(c.getArgument(i), origin) and
|
||||
e = c.getCallee().getParameter(i).getAnAccess()
|
||||
e = c.getCallee().getSourceDeclaration().getParameter(i).getAnAccess()
|
||||
)
|
||||
or
|
||||
exists(Call c, ReturnStmt r | e = c |
|
||||
r.getEnclosingCallable() = c.getCallee() and
|
||||
r.getEnclosingCallable() = c.getCallee().getSourceDeclaration() and
|
||||
iterOfSpecialCollection(r.getResult(), origin)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
||||
@@ -36,4 +36,20 @@ class A {
|
||||
public List<Integer> getL() {
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
class Parent<T> {
|
||||
|
||||
public void removeFirst(List<T> l) {
|
||||
l.iterator().remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Child extends Parent<String> {
|
||||
|
||||
public void test(String... ss) {
|
||||
removeFirst(Arrays.asList(ss));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user