IDEA-177404 Method that never returns get "returns non-null value" warning

This commit is contained in:
peter
2017-08-14 16:11:54 +02:00
parent 879e9ed76d
commit 8ac5d7c7d3
2 changed files with 11 additions and 5 deletions
@@ -348,7 +348,7 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
reportConstantReferenceValues(holder, visitor, reportedAnchors);
}
if (REPORT_NULLABLE_METHODS_RETURNING_NOT_NULL && visitor.isAlwaysReturnsNotNull()) {
if (REPORT_NULLABLE_METHODS_RETURNING_NOT_NULL && visitor.isAlwaysReturnsNotNull(runner.getInstructions())) {
reportAlwaysReturnsNotNull(holder, scope);
}
}
@@ -410,7 +410,7 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
PsiJavaCodeReferenceElement annoName = nullableAnno.getNameReferenceElement();
assert annoName != null;
String msg = "@" + NullableStuffInspectionBase.getPresentableAnnoName(nullableAnno) +
" method '" + method.getName() + "' always return a non-null value";
" method '" + method.getName() + "' always returns a non-null value";
holder.registerProblem(annoName, msg, new AddNotNullAnnotationFix(method));
}
@@ -976,8 +976,9 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
return StreamEx.ofKeys(myFailingCalls, v -> v).map(MethodCallInstruction::getCallExpression).toList();
}
boolean isAlwaysReturnsNotNull() {
return myAlwaysReturnsNotNull;
boolean isAlwaysReturnsNotNull(Instruction[] instructions) {
return myAlwaysReturnsNotNull &&
ContainerUtil.exists(instructions, i -> i instanceof ReturnInstruction && ((ReturnInstruction)i).getAnchor() instanceof PsiReturnStatement);
}
@Override
@@ -1,7 +1,7 @@
import org.jetbrains.annotations.*;
final class Foo {
@<warning descr="@Nullable method 'foo' always return a non-null value">Nullable</warning> Object foo(int param) {
@<warning descr="@Nullable method 'foo' always returns a non-null value">Nullable</warning> Object foo(int param) {
return param == 1 ? new Object() {
Object unrelated() {
return <warning descr="'null' is returned by the method which is not declared as @Nullable">null</warning>;
@@ -12,4 +12,9 @@ final class Foo {
@NotNull Foo bar() {
return this;
}
@Nullable
Object throwing() {
throw new UnsupportedOperationException();
}
}