diff --git a/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java b/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java index f218459977ef..6fb31afa813d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -378,6 +378,7 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo @Override public ProblemType getProblemType(PsiVariable optionalVariable, PsiElement trueElement, PsiElement falseElement) { if (falseElement != null && !(falseElement instanceof PsiEmptyStatement)) return ProblemType.NONE; + if (!(trueElement instanceof PsiStatement)) return ProblemType.NONE; if (trueElement instanceof PsiExpressionStatement) { PsiExpression expression = ((PsiExpressionStatement)trueElement).getExpression(); if(isOptionalGetCall(expression, optionalVariable)) return ProblemType.NONE; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/optionalIsPresent/beforeTernaryUnfinished.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/optionalIsPresent/beforeTernaryUnfinished.java new file mode 100644 index 000000000000..c7dd0de339e8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/optionalIsPresent/beforeTernaryUnfinished.java @@ -0,0 +1,9 @@ +// "Replace Optional.isPresent() condition with functional style expression" "false" + +import java.util.Optional; + +public class Main { + public void test(Optional opt) { + System.out.println(opt.isPresent() ? opt.get():); + } +} \ No newline at end of file