MismatchedCollectionQueryUpdate: tuning default method names, more tests

This commit is contained in:
Tagir Valeev
2018-01-31 17:27:41 +07:00
parent 2881cb83dd
commit 1fbb882a16
2 changed files with 31 additions and 4 deletions
@@ -57,8 +57,8 @@ public class MismatchedCollectionQueryUpdateInspectionBase extends BaseInspectio
private static final CallMatcher COLLECTION_SAFE_ARGUMENT_METHODS =
CallMatcher.anyOf(
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_COLLECTION, "addAll", "removeAll", "containsAll"),
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_MAP, "putAll")
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_COLLECTION, "addAll", "removeAll", "containsAll", "remove"),
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_MAP, "putAll", "remove")
);
private static final Set<String> COLLECTIONS_QUERIES =
@@ -72,8 +72,8 @@ public class MismatchedCollectionQueryUpdateInspectionBase extends BaseInspectio
@SuppressWarnings("PublicField")
public final ExternalizableStringSet queryNames =
new ExternalizableStringSet(
"contains", "copyInto", "equals", "forEach", "get", "hashCode", "parallelStream", "propertyNames", "replaceAll", "save",
"size", "store", "stream", "toArray", "toString", "write");
"contains", "copyInto", "equals", "forEach", "get", "hashCode", "iterator", "parallelStream", "propertyNames",
"replaceAll", "save", "size", "store", "stream", "toArray", "toString", "write");
@SuppressWarnings("PublicField")
public final ExternalizableStringSet updateNames =
new ExternalizableStringSet("add", "clear", "insert", "load", "merge", "offer", "poll", "pop", "push", "put", "remove", "replace",
@@ -84,6 +84,13 @@ public class MismatchedCollectionQueryUpdate {
return l.toArray();
}
Object[] testRemoveFromAnotherCollection(List<List<String>> list) {
List<String> <warning descr="Contents of collection 'l' are queried, but never updated">l</warning> = new ArrayList<>();
list.remove(l);
process(list);
return l.toArray();
}
native void process(List<List<String>> list);
void testPureMethod() {
@@ -147,6 +154,26 @@ public class MismatchedCollectionQueryUpdate {
nonInitialized.add(key);
}
void testListIterator() {
// IDEA-128168
List<String> test = new ArrayList<String>();
ListIterator<String> i = test.listIterator(0);
i.add("hello!");
System.out.println(i.next());
}
void testIterator() {
List<String> <warning descr="Contents of collection 'test' are queried, but never updated">test</warning> = new ArrayList<String>();
Iterator<String> i = test.iterator();
while(i.hasNext()) {
if(i.next() == null) {
// Normally iterator cannot add, remove only. If collection is always empty (not updated in any other way),
// this is useless anyways
i.remove();
}
}
}
class Node{
private SortedSet mChildren;