mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-51920 'Suspicious call to Map.get' inspection should be aware of dataflow type information
This commit is contained in:
+11
-1
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInspection.miscGenerics;
|
||||
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.guess.GuessManager;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ex.BaseLocalInspectionTool;
|
||||
@@ -133,8 +134,17 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseLocalInspect
|
||||
final IntArrayList indices) {
|
||||
final PsiExpression[] args = methodCall.getArgumentList().getExpressions();
|
||||
if (args.length != 1) return null;
|
||||
|
||||
PsiType argType = args[0].getType();
|
||||
return getSuspiciousMethodCallMessage(methodCall, argType, reportConvertibleMethodCalls, patternMethods, indices);
|
||||
final String plainMessage = getSuspiciousMethodCallMessage(methodCall, argType, reportConvertibleMethodCalls, patternMethods, indices);
|
||||
if (plainMessage != null) {
|
||||
final PsiType dfaType = GuessManager.getInstance(methodCall.getProject()).getControlFlowExpressionType(args[0]);
|
||||
if (dfaType != null && getSuspiciousMethodCallMessage(methodCall, dfaType, reportConvertibleMethodCalls, patternMethods, indices) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return plainMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.lang.Integer;
|
||||
import java.util.Map;
|
||||
|
||||
class Clazz {
|
||||
void f(Map<Integer, String> map, Object o) {
|
||||
if (o instanceof Integer && map.containsKey(o)) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
@@ -17,6 +17,7 @@ public class SuspiciousCollectionMethodCallsTest extends LightCodeInsightFixture
|
||||
myFixture.testHighlighting(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testUseDfa() throws Exception { doTest(); }
|
||||
public void testWildcard() throws Exception { doTest(); }
|
||||
public void testIgnoreConvertible() throws Exception {
|
||||
myTool.REPORT_CONVERTIBLE_METHOD_CALLS = false;
|
||||
|
||||
Reference in New Issue
Block a user