mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
relax "!null" contract checking to accept exceptions thrown (IDEA-133488)
This commit is contained in:
+1
-1
@@ -97,7 +97,7 @@ class ContractChecker extends DataFlowRunner {
|
||||
}
|
||||
|
||||
if (instruction instanceof ReturnInstruction) {
|
||||
if (((ReturnInstruction)instruction).isViaException()) {
|
||||
if (((ReturnInstruction)instruction).isViaException() && myContract.returnValue != MethodContract.ValueConstraint.NOT_NULL_VALUE) {
|
||||
ContainerUtil.addIfNotNull(myFailures, ((ReturnInstruction)instruction).getAnchor());
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Foo {
|
||||
|
||||
@Contract(value = "_, true -> !null")
|
||||
public @Nullable String noNotAllowed(@NotNull String bar, boolean reallyNotAllowed) {
|
||||
if (bar.equals("no")) {
|
||||
if (reallyNotAllowed) {
|
||||
throw new IllegalArgumentException("heck no");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
class Foo {
|
||||
@Contract("!null,true->!null")
|
||||
String delegationToInstance(@NotNull Foo f, boolean createIfNeeded) {
|
||||
return <warning descr="Contract clause '!null, true -> !null' is violated: exception might be thrown instead of returning !null">f.getString(createIfNeeded)</warning>;
|
||||
return f.getString(createIfNeeded); // not smart enough to check this
|
||||
}
|
||||
|
||||
@Contract("true->fail")
|
||||
|
||||
@@ -36,6 +36,7 @@ public class ContractCheckTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testDelegationWithUnknownArgument() { doTest(); }
|
||||
public void testEqualsUnknownValue() { doTest(); }
|
||||
public void testMissingFail() { doTest(); }
|
||||
public void testExceptionWhenDeclaredNotNull() { doTest(); }
|
||||
public void testCheckSuperContract() { doTest(); }
|
||||
public void testNestedCallsMayThrow() { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user