A DESCRIPTION OF THE PROBLEM :
Javadoc for java.util.Optional.orElseThrow(Supplier) misses mention of another one cause of NullPointerException - when exception supplying function returns a null result.
In my opinion throwing of NPE when exception supplying function returns a null result is implementation-independent behavior. This case is equal to case when exception supplying function is null.
It is worth noting that Javadocs for
java.util.Optional.or(Supplier)
java.util.Optional.flatMap(Function)
clearly highlights this cause in similar cases.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Open Javadoc for java.util.Optional.orElseThrow(Supplier)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
@throws NullPointerException if no value is present and the exception supplying function is {@code null} or exception supplying function returns a null result
ACTUAL -
@throws NullPointerException if no value is present and the exception supplying function is {@code null}
Javadoc for java.util.Optional.orElseThrow(Supplier) misses mention of another one cause of NullPointerException - when exception supplying function returns a null result.
In my opinion throwing of NPE when exception supplying function returns a null result is implementation-independent behavior. This case is equal to case when exception supplying function is null.
It is worth noting that Javadocs for
java.util.Optional.or(Supplier)
java.util.Optional.flatMap(Function)
clearly highlights this cause in similar cases.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Open Javadoc for java.util.Optional.orElseThrow(Supplier)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
@throws NullPointerException if no value is present and the exception supplying function is {@code null} or exception supplying function returns a null result
ACTUAL -
@throws NullPointerException if no value is present and the exception supplying function is {@code null}