diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java index 63df26ff3e17..a23da345e7cb 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java @@ -84,10 +84,14 @@ class ContractInferenceInterpreter { } List inferContracts() { - final boolean notNull = NullableNotNullManager.isNotNull(myMethod); + List contracts = doInferContracts(); + if (contracts.isEmpty()) return contracts; + PsiTypeElement typeElement = myMethod.getReturnTypeElement(); final PsiType returnType = typeElement == null ? null : typeElement.getType(); - return ContainerUtil.filter(doInferContracts(), new Condition() { + final boolean notNull = !(returnType instanceof PsiPrimitiveType) && + NullableNotNullManager.getInstance(myMethod.getProject()).isNotNull(myMethod, false); + return ContainerUtil.filter(contracts, new Condition() { @Override public boolean value(MethodContract contract) { if (notNull && contract.returnValue == NOT_NULL_VALUE) {