diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/InferredAnnotationsManagerImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/InferredAnnotationsManagerImpl.java
index ee4d430abb85..e4712352891a 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInsight/InferredAnnotationsManagerImpl.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInsight/InferredAnnotationsManagerImpl.java
@@ -112,6 +112,11 @@ public class InferredAnnotationsManagerImpl extends InferredAnnotationsManager {
return null;
}
+ if (NullableNotNullManager.findNullabilityDefaultInHierarchy(method, true) != null ||
+ NullableNotNullManager.findNullabilityDefaultInHierarchy(method, false) != null) {
+ return null;
+ }
+
Nullness nullness = NullityInference.inferNullity(method);
if (nullness == Nullness.NOT_NULL) {
return ProjectBytecodeAnalysis.getInstance(myProject).getNotNullAnnotation();
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 7a5465c50058..21e5e84c2b41 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
@@ -149,7 +149,6 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
private void analyzeNullLiteralMethodArguments(PsiMethod method, ProblemsHolder holder, boolean isOnTheFly) {
if (REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER) {
for (PsiParameter parameter : NullParameterConstraintChecker.checkMethodParameters(method, isOnTheFly)) {
- final String name = parameter.getName();
holder.registerProblem(parameter.getNameIdentifier(),
InspectionsBundle.message("dataflow.method.fails.with.null.argument"),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
@@ -609,8 +608,8 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
final PsiMethod method = getScopeMethod(block);
if (method == null || NullableStuffInspectionBase.isNullableNotInferred(method, true)) return;
- boolean notNullRequired = NullableNotNullManager.isNotNull(method);
- if (!notNullRequired && !SUGGEST_NULLABLE_ANNOTATIONS) return;
+ PsiAnnotation notNullAnno = NullableNotNullManager.getInstance(method.getProject()).getNotNullAnnotation(method, true);
+ if (notNullAnno == null && !SUGGEST_NULLABLE_ANNOTATIONS) return;
PsiType returnType = method.getReturnType();
// no warnings in void lambdas, where the expression is not returned anyway
@@ -624,10 +623,11 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
final PsiExpression expr = (PsiExpression)statement;
if (!reportedAnchors.add(expr)) continue;
- if (notNullRequired) {
+ if (notNullAnno != null) {
+ String presentable = NullableStuffInspectionBase.getPresentableAnnoName(notNullAnno);
final String text = isNullLiteralExpression(expr)
- ? InspectionsBundle.message("dataflow.message.return.null.from.notnull")
- : InspectionsBundle.message("dataflow.message.return.nullable.from.notnull");
+ ? InspectionsBundle.message("dataflow.message.return.null.from.notnull", presentable)
+ : InspectionsBundle.message("dataflow.message.return.nullable.from.notnull", presentable);
holder.registerProblem(expr, text);
}
else if (AnnotationUtil.isAnnotatingApplicable(statement)) {
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java
index e4043a483aa0..dafd03e4bcea 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java
@@ -332,7 +332,7 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
return StringUtil.getShortName(anno != null ? anno : StringUtil.notNullize(manager.getNullable(owner), "???"));
}
- private static String getPresentableAnnoName(@NotNull PsiAnnotation annotation) {
+ public static String getPresentableAnnoName(@NotNull PsiAnnotation annotation) {
return StringUtil.getShortName(StringUtil.notNullize(annotation.getQualifiedName(), "???"));
}
diff --git a/java/java-psi-api/src/com/intellij/codeInsight/NullableNotNullManager.java b/java/java-psi-api/src/com/intellij/codeInsight/NullableNotNullManager.java
index 4fe312874149..feae72973754 100644
--- a/java/java-psi-api/src/com/intellij/codeInsight/NullableNotNullManager.java
+++ b/java/java-psi-api/src/com/intellij/codeInsight/NullableNotNullManager.java
@@ -270,7 +270,7 @@ public abstract class NullableNotNullManager implements PersistentStateComponent
}
@Nullable
- private static PsiAnnotation findNullabilityDefaultInHierarchy(PsiModifierListOwner owner, boolean nullable) {
+ static PsiAnnotation findNullabilityDefaultInHierarchy(PsiModifierListOwner owner, boolean nullable) {
PsiAnnotation.TargetType[] placeTargetTypes = AnnotationTargetUtil.getTargetsForLocation(owner.getModifierList());
PsiElement element = owner.getParent();
diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/CustomDefaultInEnums.java b/java/java-tests/testData/inspection/dataFlow/fixture/CustomDefaultInEnums.java
index 2c9bbfc80592..37e27f652585 100644
--- a/java/java-tests/testData/inspection/dataFlow/fixture/CustomDefaultInEnums.java
+++ b/java/java-tests/testData/inspection/dataFlow/fixture/CustomDefaultInEnums.java
@@ -10,12 +10,12 @@ enum TestNonnull {
if (aObject == null) {
return new Object();
}
- return null;
+ return null;
}
@Override
public Object testWithoutAnnotation(Object aObject) {
- return null;
+ return null;
}
};
@@ -27,7 +27,7 @@ enum TestNonnull {
}
public Object testReturn() {
- return null;
+ return null;
}
@Nonnull
diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java b/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java
index 47df47f35b44..18f9be2c43d6 100644
--- a/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java
+++ b/java/java-tests/testData/inspection/dataFlow/fixture/CustomTypeQualifierDefault.java
@@ -21,7 +21,11 @@ class NotNullClass {
static native Object foo(String s);
public Object foo() {
- return null;
+ return null;
+ }
+
+ private Object privateFoo() {
+ return null;
}
@Nullable
diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties
index 8f682aeeb0b0..8c5e9035c7b0 100644
--- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties
+++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties
@@ -81,12 +81,11 @@ dataflow.message.constant.condition.when.reached=Condition #ref #lo
dataflow.message.unreachable.switch.label=Switch label#ref #loc is unreachable
dataflow.message.pointless.assignment.expression=Condition #ref #loc at the left side of assignment expression is always {0}. Can be simplified
dataflow.message.passing.null.argument=Passing null argument to parameter annotated as @NotNull
-dataflow.message.initializing.field.with.null=Field annotated as @NotNull is implicitly initialized with null
dataflow.message.passing.nullable.argument=Argument #ref #loc might be null
dataflow.message.assigning.null=null is assigned to a variable that is annotated with @NotNull
dataflow.message.assigning.nullable=Expression #ref might evaluate to null but is assigned to a variable that is annotated with @NotNull
-dataflow.message.return.null.from.notnull=null is returned by the method declared as @NotNull
-dataflow.message.return.nullable.from.notnull=Expression #ref might evaluate to null but is returned by the method declared as @NotNull
+dataflow.message.return.null.from.notnull=null is returned by the method declared as @{0}
+dataflow.message.return.nullable.from.notnull=Expression #ref might evaluate to null but is returned by the method declared as @{0}
dataflow.message.return.null.from.notnullable=null is returned by the method which is not declared as @{0}
dataflow.message.return.nullable.from.notnullable=Expression #ref might evaluate to null but is returned by the method which is not declared as @{0}
dataflow.message.unboxing=Unboxing of #ref #loc may produce java.lang.NullPointerException