diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java index abb7d3fc5038..fb7f7653a16a 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -465,12 +465,15 @@ public class ExceptionUtil { final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(methodCall, PsiLambdaExpression.class); final PsiSubstitutor substitutor; if (expression != null) { - substitutor = ourThrowsGuard.doPreventingRecursion(expression, false, new Computable() { + final PsiElement parent = methodCall.getParent(); + final boolean callInReturnStatement = parent == expression || + parent instanceof PsiReturnStatement && PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, true, PsiMethod.class) == expression; + substitutor = callInReturnStatement ? ourThrowsGuard.doPreventingRecursion(expression, false, new Computable() { @Override public PsiSubstitutor compute() { return result.getSubstitutor(); } - }); + }) : result.getSubstitutor(); } else { substitutor = result.getSubstitutor(); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CheckedExceptionsConstraintsSubstitutionsDeepInBody.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CheckedExceptionsConstraintsSubstitutionsDeepInBody.java new file mode 100644 index 000000000000..42ceb7b84b17 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CheckedExceptionsConstraintsSubstitutionsDeepInBody.java @@ -0,0 +1,20 @@ +import java.io.IOException; +import java.util.Optional; + +class Test { + + interface Extractor { + T extractData() throws IOException; + } + + public static T query(Extractor rse) { + return null; + } + + static { + final Optional query = query(() -> { + final String type = Optional.empty().orElseThrow(null); + return null; + }); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java index 5df6f0907d6e..9ed3666e622f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java @@ -140,6 +140,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testCheckedExceptionsConstraintsSubstitutionsDeepInBody() throws Exception { + doTest(); + } + public void testIDEA130129() throws Exception { doTest(); }