void (ProblemReporter reporter, List<NullabilityProblem<?>> problems) { for (NullabilityProblem<?> problem : problems) { PsiExpression expression = problem.getDereferencedExpression(); boolean nullLiteral = ExpressionUtils.isNullLiteral(expression); if (!REPORT_UNSOUND_WARNINGS) { if (expression == null || !nullLiteral && CommonDataflow.getDfType(expression, IGNORE_ASSERT_STATEMENTS) != DfTypes.NULL) continue; } // Expression of null type: could be failed LVTI, skip it to avoid confusion if (expression != null && !nullLiteral && PsiTypes.nullType().equals(expression.getType())) continue; boolean alwaysNull = problem.isAlwaysNull(IGNORE_ASSERT_STATEMENTS); NullabilityProblemKind.innerClassNPE.ifMyProblem(problem, newExpression -> { List<LocalQuickFix> fixes = createNPEFixes(newExpression.getQualifier(), newExpression, reporter.isOnTheFly(), alwaysNull); reporter .registerProblem(getElementToHighlight(newExpression), problem.getMessage(IGNORE_ASSERT_STATEMENTS), fixes.toArray(LocalQuickFix.EMPTY_ARRAY)); }); NullabilityProblemKind.callMethodRefNPE.ifMyProblem(problem, methodRef -> reporter.registerProblem(methodRef, JavaAnalysisBundle.message("dataflow.message.npe.methodref.invocation"), createMethodReferenceNPEFixes(methodRef, reporter.isOnTheFly()).toArray(LocalQuickFix.EMPTY_ARRAY))); NullabilityProblemKind.callNPE.ifMyProblem(problem, call -> reportCallMayProduceNpe(reporter, problem.getMessage(IGNORE_ASSERT_STATEMENTS), call, alwaysNull)); NullabilityProblemKind.passingToNotNullParameter.ifMyProblem(problem, expr -> { List<LocalQuickFix> fixes = createNPEFixes(expression, expression, reporter.isOnTheFly(), alwaysNull); reporter.registerProblem(expression, problem.getMessage(IGNORE_ASSERT_STATEMENTS), fixes.toArray(LocalQuickFix.EMPTY_ARRAY)); }); NullabilityProblemKind.passingToNotNullMethodRefParameter.ifMyProblem(problem, methodRef -> { LocalQuickFix[] fixes = createMethodReferenceNPEFixes(methodRef, reporter.isOnTheFly()).toArray(LocalQuickFix.EMPTY_ARRAY); reporter.registerProblem(methodRef, JavaAnalysisBundle.message("dataflow.message.passing.nullable.argument.methodref"), fixes); }); NullabilityProblemKind.unboxingMethodRefParameter.ifMyProblem(problem, methodRef -> { LocalQuickFix[] fixes = createMethodReferenceNPEFixes(methodRef, reporter.isOnTheFly()).toArray(LocalQuickFix.EMPTY_ARRAY); reporter.registerProblem(methodRef, JavaAnalysisBundle.message("dataflow.message.unboxing.nullable.argument.methodref"), fixes); }); NullabilityProblemKind.arrayAccessNPE.ifMyProblem(problem, arrayAccess -> { LocalQuickFix[] fixes = createNPEFixes(arrayAccess.getArrayExpression(), arrayAccess, reporter.isOnTheFly(), alwaysNull).toArray(LocalQuickFix.EMPTY_ARRAY); reporter.registerProblem(arrayAccess, problem.getMessage(IGNORE_ASSERT_STATEMENTS), fixes); }); NullabilityProblemKind.templateNPE.ifMyProblem(problem, template -> { PsiExpression processor = template.getProcessor(); LocalQuickFix[] fixes = createNPEFixes(processor, template, reporter.isOnTheFly(), alwaysNull).toArray(LocalQuickFix.EMPTY_ARRAY); reporter.registerProblem(processor, problem.getMessage(IGNORE_ASSERT_STATEMENTS), fixes); }); NullabilityProblemKind.fieldAccessNPE.ifMyProblem(problem, element -> { PsiElement parent = element.getParent(); PsiExpression fieldAccess = parent instanceof PsiReferenceExpression ? (PsiExpression)parent : element; LocalQuickFix[] fix = createNPEFixes(element, fieldAccess, reporter.isOnTheFly(), alwaysNull).toArray(LocalQuickFix.EMPTY_ARRAY); reporter.registerProblem(element, problem.getMessage(IGNORE_ASSERT_STATEMENTS), fix); }); NullabilityProblemKind.unboxingNullable.ifMyProblem(problem, element -> { PsiExpression anchor = expression; if (anchor instanceof PsiTypeCastExpression && anchor.getType() instanceof PsiPrimitiveType) { anchor = Objects.requireNonNull(((PsiTypeCastExpression)anchor).getOperand()); } if (anchor != null) { LocalQuickFix[] fixes = createUnboxingNullableFixes(anchor, element, reporter.isOnTheFly()).toArray(LocalQuickFix.EMPTY_ARRAY); reporter.registerProblem(anchor, problem.getMessage(IGNORE_ASSERT_STATEMENTS), fixes); } }); NullabilityProblemKind.nullableFunctionReturn.ifMyProblem( problem, expr -> reporter.registerProblem(expression == null ? expr : expression, problem.getMessage(IGNORE_ASSERT_STATEMENTS))); Consumer<PsiExpression> reportNullability = expr -> reportNullabilityProblem(reporter, problem, expression); NullabilityProblemKind.assigningToNotNull.ifMyProblem(problem, reportNullability); NullabilityProblemKind.storingToNotNullArray.ifMyProblem(problem, reportNullability); if (SUGGEST_NULLABLE_ANNOTATIONS) { NullabilityProblemKind.passingToNonAnnotatedMethodRefParameter.ifMyProblem( problem, methodRef -> reportNullableArgumentPassedToNonAnnotatedMethodRef(reporter, problem, methodRef)); NullabilityProblemKind.passingToNonAnnotatedParameter.ifMyProblem( problem, top -> reportNullableArgumentsPassedToNonAnnotated(reporter, problem.getMessage(IGNORE_ASSERT_STATEMENTS), expression, top, alwaysNull)); NullabilityProblemKind.assigningToNonAnnotatedField.ifMyProblem( problem, top -> reportNullableAssignedToNonAnnotatedField(reporter, top, expression, problem.getMessage(IGNORE_ASSERT_STATEMENTS), alwaysNull)); } } }