mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-10 18:09:38 +07:00
IDEA-276924 Incorrect ConstantConditions inspection warning in combination with Optional GitOrigin-RevId: aba1f4a9f832423626c5e8c64d2777def48df2bc
36 lines
776 B
Java
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;
|
|
}
|
|
}
|
|
|
|
} |