A DESCRIPTION OF THE PROBLEM :
Javadoc for java.util.Optional.orElseThrow(Supplier) misses mentioning of another possible cause of a NullPointerException - when the 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 the 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 produces a {@code 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 mentioning of another possible cause of a NullPointerException - when the 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 the 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 produces a {@code null} result
ACTUAL -
@throws NullPointerException if no value is present and the exception supplying function is {@code null}
- csr for
-
JDK-8354953 Optional.orElseThrow(Supplier) does not specify behavior when supplier returns null
-
- Closed
-
- links to
-
Commit(master) openjdk/jdk/44374a57
-
Review(master) openjdk/jdk/23905