relax "!null" contract checking to accept exceptions thrown (IDEA-133488)

This commit is contained in:
peter
2015-04-08 18:13:15 +02:00
parent 5c964ca6fc
commit 4ec8011316
4 changed files with 20 additions and 2 deletions
@@ -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")