void (ProblemReporter reporter, List<NullabilityProblem<?>> problems, @NotNull PsiElement block) { final PsiMethod method = getScopeMethod(block); if (method == null) return; NullableNotNullManager manager = NullableNotNullManager.getInstance(method.getProject()); NullabilityAnnotationInfo info = manager.findEffectiveNullabilityInfo(method); if (info == null) info = DfaPsiUtil.getTypeNullabilityInfo(PsiTypesUtil.getMethodReturnType(block)); PsiAnnotation anno = info == null ? null : info.getAnnotation(); Nullability nullability = info == null ? Nullability.UNKNOWN : info.getNullability(); PsiType returnType = method.getReturnType(); if (nullability == Nullability.NULLABLE) { if (!info.isInferred() || DfaPsiUtil.getTypeNullability(returnType) == Nullability.NULLABLE) return; } // In rare cases, inference may produce different result (e.g. if nullable method overrides non-null method) if (nullability == Nullability.NOT_NULL && info.isInferred()) return; if (nullability != Nullability.NOT_NULL && (!SUGGEST_NULLABLE_ANNOTATIONS || block.getParent() instanceof PsiLambdaExpression)) return; // no warnings in void lambdas, where the expression is not returned anyway if (block instanceof PsiExpression && block.getParent() instanceof PsiLambdaExpression && PsiTypes.voidType().equals(returnType)) return; // no warnings for Void methods, where only null can be possibly returned if (returnType == null || returnType.equalsToText(CommonClassNames.JAVA_LANG_VOID)) return; for (NullabilityProblem<PsiExpression> problem : StreamEx.of(problems).map(NullabilityProblemKind.nullableReturn::asMyProblem).nonNull()) { final PsiExpression anchor = problem.getAnchor(); PsiExpression expr = problem.getDereferencedExpression(); boolean exactlyNull = problem.isAlwaysNull(IGNORE_ASSERT_STATEMENTS); if (!REPORT_UNSOUND_WARNINGS && !exactlyNull) continue; if (nullability == Nullability.NOT_NULL) { String presentable = NullableStuffInspectionBase.getPresentableAnnoName(anno); final String text = exactlyNull ? JavaAnalysisBundle.message("dataflow.message.return.null.from.notnull", presentable) : JavaAnalysisBundle.message("dataflow.message.return.nullable.from.notnull", presentable); reporter.registerProblem(expr, text, createNPEFixes(expr, expr, reporter.isOnTheFly(), exactlyNull).toArray(LocalQuickFix.EMPTY_ARRAY)); } else if (AnnotationUtil.isAnnotatingApplicable(anchor)) { final String defaultNullable = manager.getDefaultNullable(); final String presentableNullable = StringUtil.getShortName(defaultNullable); final String text = exactlyNull ? JavaAnalysisBundle.message("dataflow.message.return.null.from.notnullable", presentableNullable) : JavaAnalysisBundle.message("dataflow.message.return.nullable.from.notnullable", presentableNullable); PsiMethod surroundingMethod = PsiTreeUtil.getParentOfType(anchor, PsiMethod.class, true, PsiLambdaExpression.class); final LocalQuickFix fix = surroundingMethod == null ? null : new AddAnnotationPsiFix(defaultNullable, surroundingMethod, ArrayUtilRt.toStringArray(manager.getNotNulls())); reporter.registerProblem(expr, text, LocalQuickFix.notNullElements(fix)); } } }