You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive with Optional.or method and JSpecify #1611
While trying to update NullAway from 0.13.4 to 0.13.7, there's an issue with JSpecify and handling Optional.or(Supplier<Optional<T>>) method.
I've prepared a following sample:
@NullMarked
public class Main {
public static Optional<String> getKey(@Nullable String key) {
return Optional.ofNullable(key).or(() -> Optional.ofNullable(System.getenv("DEFAULT_KEY")));
}
public static void main() {
Optional<String> code = getKey("TEST_KEY");
code.ifPresent(s -> System.out.println("Value: " + s));
}
}
Execution failed for task ':compileJava' (registered by plugin class 'org.gradle.api.plugins.JavaBasePlugin').
> Compilation failed; see the compiler output below.
/home/damian/repo/nullaway-optional-issue/src/main/java/org/example/Main.java:11: error: [NullAway] incompatible types: Optional<@Nullable String> cannot be converted to Optional<String>
return Optional.ofNullable(key).or(() -> Optional.ofNullable(System.getenv("DEFAULT_KEY")));
^
(see http://t.uber.com/nullaway )
1 error
I would assume that in this case, the point of or method is to also allow Optional that might also be empty.
This seems related to #1594. There seem to be various ways which Nullaway can be tricked into thinking an Optional<@Nullable Object> is possible, even though it is impossible under all circumstances.
Activity
msridhar commentedon Jun 17, 2026
Thanks for the report! I think this might be related to #950 but when I get a bit of time I'll dig more and confirm; maybe we can do a narrower fix.
lbenedetto commentedon Jun 18, 2026
This seems related to #1594. There seem to be various ways which Nullaway can be tricked into thinking an
Optional<@Nullable Object>is possible, even though it is impossible under all circumstances.Add more modeling for Optional (#1613)