// Test case for issue 557: // https://github.com/typetools/checker-framework/issues/557 import java.util.Optional; import org.checkerframework.checker.nullness.qual.Nullable; @SuppressWarnings("nullness") class MyOpt { static MyOpt of(S p) { return null; } static MyOpt empty() { return null; } } @SuppressWarnings("nullness") class MyOpt2 { static MyOpt2 of(S p) { return null; } static MyOpt2 empty() { return null; } } @SuppressWarnings("nullness") class MyOpt3 { static MyOpt3 of(S p) { return null; } static MyOpt3 empty() { return null; } } class Issue557a { MyOpt opt(boolean flag) { return flag ? MyOpt.of("Hello") : MyOpt.empty(); } MyOpt opt2() { return MyOpt.empty(); } MyOpt opt3(boolean flag) { return flag ? MyOpt.of("Hello") : (flag ? MyOpt.empty() : MyOpt.empty()); } void foo(MyOpt param) {} void callFoo(boolean flag) { foo(flag ? MyOpt.of("Hello") : (flag ? MyOpt.empty() : MyOpt.empty())); } } class Issue557b { MyOpt2 opt(boolean flag) { return flag ? MyOpt2.of("Hello") : MyOpt2.empty(); } MyOpt2 opt2() { return MyOpt2.empty(); } } class Issue557c { MyOpt3 opt(boolean flag) { return flag ? MyOpt3.of("Hello") : MyOpt3.empty(); } MyOpt3 opt2() { return MyOpt3.empty(); } } class Issue557d { Optional opt(boolean flag) { return flag ? Optional.of("Hello") : Optional.empty(); } Optional opt2() { return Optional.empty(); } }