Optional.get() is called without isPresent() check
Reports calls to get()
on an Optional
without checking that it has a value.
Calling Optional.get()
on an empty Optional
instance will throw an exception.
Example:
void x(List<Integer> list) {
final Optional<Integer> optional =
list.stream().filter(x -> x > 10).findFirst();
final Integer result = optional.get(); // problem here
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023