Fix java/iterator-remove-failure to handle calls to specialised generic functions

This commit is contained in:
Chris Smowton
2022-09-14 17:09:47 +01:00
parent 3bdccb38b6
commit c149754c6b
3 changed files with 21 additions and 4 deletions

View File

@@ -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)
)
}

View File

@@ -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 |

View File

@@ -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));
}
}