mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-196563 Wrong “Contract issue” inspection stating a method always fails
This commit is contained in:
+9
-9
@@ -70,10 +70,18 @@ class ContractChecker extends DataFlowRunner {
|
||||
@Override
|
||||
protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) {
|
||||
DfaMemoryState memState = instructionState.getMemoryState();
|
||||
Instruction instruction = instructionState.getInstruction();
|
||||
if (instruction instanceof ReturnInstruction) {
|
||||
if (((ReturnInstruction)instruction).isViaException()) {
|
||||
ContainerUtil.addIfNotNull(myFailures, ((ReturnInstruction)instruction).getAnchor());
|
||||
} else {
|
||||
myMayReturnNormally = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (memState.isEphemeral()) {
|
||||
return super.acceptInstruction(visitor, instructionState);
|
||||
}
|
||||
Instruction instruction = instructionState.getInstruction();
|
||||
if (instruction instanceof CheckReturnValueInstruction) {
|
||||
PsiElement anchor = ((CheckReturnValueInstruction)instruction).getReturn();
|
||||
DfaValue retValue = memState.pop();
|
||||
@@ -86,14 +94,6 @@ class ContractChecker extends DataFlowRunner {
|
||||
|
||||
}
|
||||
|
||||
if (instruction instanceof ReturnInstruction) {
|
||||
if (((ReturnInstruction)instruction).isViaException()) {
|
||||
ContainerUtil.addIfNotNull(myFailures, ((ReturnInstruction)instruction).getAnchor());
|
||||
} else {
|
||||
myMayReturnNormally = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (instruction instanceof MethodCallInstruction &&
|
||||
((MethodCallInstruction)instruction).getMethodType() == MethodCallInstruction.MethodType.REGULAR_METHOD_CALL) {
|
||||
if (myContract.getReturnValue().isFail()) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
class Foo {
|
||||
// IDEA-196563
|
||||
@Nullable
|
||||
@Contract(pure = true, value = "null, _, true -> fail; _, _, true -> !null")
|
||||
private static Object getParam(@Nullable Map<String, Object> params, @NotNull String paramName, boolean required) {
|
||||
final Object value = params == null ? null : params.get(paramName);
|
||||
if (value == null && required) {
|
||||
throw new IllegalArgumentException("Parameter not found");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -54,4 +54,5 @@ public class ContractCheckTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testMutationSignatureProblems() { doTest(); }
|
||||
public void testNewThisParam() { doTest(); }
|
||||
public void testConditionsConflict() { doTest(); }
|
||||
public void testWrongFailSuggestion() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user