import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; class Foo { @Nullable @Contract ( "_ -> null") String foo(String s) { return "42"; } }