mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-161257 Map.computeIfAbsent: disable inspection if checked exception is thrown from lambda body
This commit is contained in:
+2
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.java18api;
|
||||
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
@@ -179,6 +180,7 @@ public class Java8CollectionsApiInspection extends BaseJavaBatchLocalInspectionT
|
||||
!equivalence.expressionsAreEquivalent(value, putArguments[1])) {
|
||||
return;
|
||||
}
|
||||
if(!ExceptionUtil.getThrownCheckedExceptions(new PsiElement[] {lambdaCandidate}).isEmpty()) return;
|
||||
PsiElement[] varRefs = PsiTreeUtil.collectElements(lambdaCandidate, e -> e instanceof PsiReferenceExpression &&
|
||||
((PsiReferenceExpression)e)
|
||||
.resolve() instanceof PsiVariable);
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "false"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends ArrayList<String> {
|
||||
public MyList() throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testMap(Map<String, List<String>> map, String key, String value) throws Exception {
|
||||
List<String> list = map.get(key);
|
||||
if(list == nul<caret>l) {
|
||||
list = new MyList();
|
||||
map.put(key, list);
|
||||
}
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user