Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/OptionalAsQualifier.java
Tagir Valeev 58b3f11a83 [java-dfa] Preserve accessor as variable having Optional.get as qualifier
IDEA-276924 Incorrect ConstantConditions inspection warning in combination with Optional

GitOrigin-RevId: aba1f4a9f832423626c5e8c64d2777def48df2bc
2021-08-31 14:32:54 +00:00

36 lines
776 B
Java

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public class OptionalAsQualifier {
private static void example(@Nullable Container value) {
Optional<Container> optional = Optional.ofNullable(value);
if (optional.isPresent() && optional.get().getValue() != null) {
foo(optional.get().getValue());
}
if (value != null) {
if (value.getValue() != null) {
foo(value.getValue());
}
}
}
private static void foo(@NotNull Object val) {}
private static class Container {
@Nullable private final Object val;
private Container(@Nullable Object val) {
this.val = val;
}
@Nullable
public Object getValue() {
return val;
}
}
}