mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-dfa] Ignore some contracts if method return value is not used
GitOrigin-RevId: 2834d00f1385759947351f8b93d8fc6a18a45106
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cbdf7bb2f9
commit
a3e6b55f19
+5
@@ -1710,6 +1710,11 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
anchor = reference;
|
||||
}
|
||||
else {
|
||||
if (ExpressionUtils.isVoidContext(expression) && ContainerUtil.all(contracts, c ->
|
||||
c.getReturnValue() != ContractReturnValue.fail() && !(c.getReturnValue() instanceof ContractReturnValue.ParameterReturnValue))) {
|
||||
// Do not track contracts if return value is not used
|
||||
contracts = Collections.emptyList();
|
||||
}
|
||||
addInstruction(new MethodCallInstruction(expression, myFactory.createValue(expression), contracts));
|
||||
anchor = expression;
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class Inspection {
|
||||
|
||||
@Nullable
|
||||
private Object o;
|
||||
|
||||
public void test1() {
|
||||
check(o);
|
||||
foo(<warning descr="Argument 'o' might be null">o</warning>);
|
||||
}
|
||||
|
||||
public static Object check(@Nullable final Object o) {
|
||||
if (o != null && is()) {
|
||||
}
|
||||
return <warning descr="'null' is returned by the method which is not declared as @Nullable">null</warning>;
|
||||
}
|
||||
|
||||
private static boolean is() {
|
||||
System.out.println();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void foo(@NotNull final Object obj) {
|
||||
}
|
||||
}
|
||||
@@ -693,4 +693,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testFinalStaticFields() { doTest(); }
|
||||
public void testReassignInConstructor() { doTest(); }
|
||||
public void testCollectionViewsSize() { doTest(); }
|
||||
public void testFlushedNullableOnUnknownCall() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user