diff --git a/java/java-impl/src/com/intellij/codeInspection/util/OptionalUtil.java b/java/java-impl/src/com/intellij/codeInspection/util/OptionalUtil.java index 6b1f5ace8a97..5c07df7115db 100644 --- a/java/java-impl/src/com/intellij/codeInspection/util/OptionalUtil.java +++ b/java/java-impl/src/com/intellij/codeInspection/util/OptionalUtil.java @@ -228,8 +228,10 @@ public class OptionalUtil { @NotNull private static String getMapTypeArgument(PsiExpression expression, PsiType type, PsiExpression falseExpression) { if (!(type instanceof PsiClassType)) return ""; - PsiExpression copy = - JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(expression.getText(), expression); + String text = expression.getText(); + // PsiEmptyExpressionImpl might be passed here + if (text.isEmpty()) return ""; + PsiExpression copy = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(text, expression); PsiType exprType = copy.getType(); if (exprType != null && !exprType.equals(PsiType.NULL) && diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/collect/afterCollectIncomplete.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/collect/afterCollectIncomplete.java new file mode 100644 index 000000000000..e75caae736a7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/collect/afterCollectIncomplete.java @@ -0,0 +1,11 @@ +// "Replace with collect" "true" + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class Main { + void test(List list) { + List result = list.stream().map(s ->).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/collect/beforeCollectIncomplete.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/collect/beforeCollectIncomplete.java new file mode 100644 index 000000000000..68ce89146ab2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/collect/beforeCollectIncomplete.java @@ -0,0 +1,13 @@ +// "Replace with collect" "true" + +import java.util.ArrayList; +import java.util.List; + +public class Main { + void test(List list) { + List result = new ArrayList<>(); + for (String s : list) { + result.add(; + } + } +} \ No newline at end of file