Inspectopedia
 
2024.3

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:

This inspection depends on the Java feature 'Stream and Optional API', which is available since Java 8.