diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java index 241b2615dc6d..a90c3f497478 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java @@ -863,14 +863,14 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool for (NullabilityProblem problem : visitor.problems().map(NullabilityProblemKind.nullableReturn::asMyProblem).nonNull()) { final PsiExpression anchor = problem.getAnchor(); - PsiExpression expr = PsiUtil.skipParenthesizedExprDown(anchor); + PsiExpression expr = problem.getDereferencedExpression(); if (nullability == Nullability.NOT_NULL) { String presentable = NullableStuffInspectionBase.getPresentableAnnoName(anno); final String text = isNullLiteralExpression(expr) || visitor.getConstantExpressions().get(expr) == ConstantResult.NULL ? InspectionsBundle.message("dataflow.message.return.null.from.notnull", presentable) : InspectionsBundle.message("dataflow.message.return.nullable.from.notnull", presentable); - reporter.registerProblem(anchor, text); + reporter.registerProblem(expr, text); } else if (AnnotationUtil.isAnnotatingApplicable(anchor)) { final String defaultNullable = manager.getDefaultNullable(); @@ -882,7 +882,7 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool PsiTreeUtil.getParentOfType(anchor, PsiMethod.class, PsiLambdaExpression.class) instanceof PsiLambdaExpression ? LocalQuickFix.EMPTY_ARRAY : new LocalQuickFix[]{ new AnnotateMethodFix(defaultNullable, ArrayUtil.toStringArray(manager.getNotNulls()))}; - reporter.registerProblem(anchor, text, fixes); + reporter.registerProblem(expr, text, fixes); } } } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java b/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java index 04135958aeab..6135f003eefd 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java @@ -31,7 +31,7 @@ class Test { @NotNull Object testReturn(Object x1, Object x2) { if(x1 == null) return x1; - if(x2 == null) return (x2); + if(x2 == null) return (x2); return new Object(); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/TernaryNullability.java b/java/java-tests/testData/inspection/dataFlow/fixture/TernaryNullability.java index 1ffdc2122a24..03e43f812bdc 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/TernaryNullability.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/TernaryNullability.java @@ -13,4 +13,8 @@ final class MyClass { cons(f1 ? f2 ? a : b : ((Object)c)); cons(f1 ? f2 ? a : b : f2 ? c : new Object()); } + + @NotNull String testReturn(boolean b) { + return b ? "hello" : null; + } } \ No newline at end of file