Java
Optional.get() is called without isPresent() check
Warning
New
Last modified: 03 December 2024 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
}
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
OptionalGetWithoutIsPresent
This inspection depends on the Java feature 'Stream and Optional API', which is available since Java 8.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |
Thanks for your feedback!
Was this page helpful?