mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-177404 Method that never returns get "returns non-null value" warning
This commit is contained in:
+5
-4
@@ -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
|
||||
|
||||
+6
-1
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user