mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suspicious call should ignore captured wildcard types assignments (IDEADEV-39955)
This commit is contained in:
@@ -21,6 +21,7 @@ public class SuspiciousCollectionMethodCallsTest extends InspectionTestCase {
|
||||
}
|
||||
|
||||
public void testWildcardCapture() throws Exception { doTest(); }
|
||||
public void testWildcard() throws Exception { doTest(); }
|
||||
public void testIgnoreConvertible() throws Exception {
|
||||
myTool.REPORT_CONVERTIBLE_METHOD_CALLS = false;
|
||||
doTest();
|
||||
|
||||
+3
@@ -143,6 +143,9 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseLocalInspect
|
||||
PsiType typeParamMapping = substitutor.substitute(typeParameter);
|
||||
if (typeParamMapping == null) return;
|
||||
String message = null;
|
||||
if (typeParamMapping instanceof PsiCapturedWildcardType) {
|
||||
typeParamMapping = ((PsiCapturedWildcardType)typeParamMapping).getWildcard();
|
||||
}
|
||||
if (!typeParamMapping.isAssignableFrom(argType)) {
|
||||
if (typeParamMapping.isConvertibleFrom(argType)) {
|
||||
if (REPORT_CONVERTIBLE_METHOD_CALLS) {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>13</line>
|
||||
<description>'List<? extends Number>' may not contain objects of type 'String'</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
|
||||
@@ -8,4 +8,8 @@ class Clazz {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void foo(List<? extends Number> c) {
|
||||
c.contains("");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>6</line>
|
||||
<description>'List<? extends Number>' may not contain objects of type 'String'</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class Clazz {
|
||||
void foo(List<? extends Number> l) {
|
||||
boolean b = l.contains("");
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>7</line>
|
||||
<description>Suspicious call to 'List.indexOf'</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user