Back to Intellij Community

ThrowableSupplierOnlyThrowException

java/java-impl/resources/inspectionDescriptions/ThrowableSupplierOnlyThrowException.html

2025.3-rc-2309 B
Original Source

Reports Supplier lambdas in Optional.orElseThrow() calls that throw an exception, instead of returning it.

Example:

optional.orElseThrow(() -> {
    throw new RuntimeException();
});

After the quick-fix is applied:

optional.orElseThrow(() -> new RuntimeException());

New in 2023.1