suspicious method calls: don't ignore array types, captures, etc (IDEA-153097)

This commit is contained in:
Anna.Kozlova
2016-03-21 14:14:26 +01:00
parent f14159a852
commit 348b89190c
3 changed files with 36 additions and 1 deletions
@@ -0,0 +1,31 @@
import java.util.ArrayList;
import java.util.List;
class Main {
void suspicious(Object[][] data) {
List<String> stringList = new ArrayList<>();
stringList.remove(<warning descr="'List<String>' may not contain objects of type 'Object[][]'">data</warning>);
stringList.remove(<warning descr="'List<String>' may not contain objects of type 'Object[]'">data[0]</warning>);
stringList.remove(<warning descr="Suspicious call to 'List.remove'">data[0][0]</warning>);
stringList.contains(<warning descr="'List<String>' may not contain objects of type 'Object[][]'">data</warning>);
stringList.contains(<warning descr="'List<String>' may not contain objects of type 'Object[]'">data[0]</warning>);
stringList.contains(<warning descr="Suspicious call to 'List.contains'">data[0][0]</warning>);
M<? extends String> m = new M<>();
stringList.contains(m.get());
M<? super String> m1 = new M<>();
stringList.contains(<warning descr="Suspicious call to 'List.contains'">m1.get()</warning>);
M<?> m2 = new M<>();
stringList.contains(<warning descr="Suspicious call to 'List.contains'">m2.get()</warning>);
}
class M<T> {
public T get() {
return null;
}
}
}
@@ -29,6 +29,10 @@ public class SuspiciousCollectionMethodCallsTest extends LightCodeInsightFixture
doTest();
}
public void testNonClassArgTypes() throws Exception {
doTest();
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {