Wrong exception in ComputedConstant#orElse Javadoc
Daniel Schmid
daniel at wwwmaster.at
Fri Aug 4 16:55:19 UTC 2023
When viewing the propsed Javadoc of ComputedConstant#orElse
(https://cr.openjdk.org/~pminborg/computed-constant/api/java.base/java/lang/ComputedConstant.html#orElse(V)),it
mentions throwing an NoSuchElementException in case the element cannot
be bound.
However, the Javadoc also mentions returning the passed value in that case.
If we take a look at the code for that in the Leyden repository
(https://github.com/openjdk/leyden/blob/b9219784cc277417dc112a7fbf652bdc021cf806/src/java.base/share/classes/jdk/internal/constant/AbstractComputedConstant.java#L127
and
https://github.com/openjdk/leyden/blob/b9219784cc277417dc112a7fbf652bdc021cf806/src/java.base/share/classes/jdk/internal/constant/AbstractComputedConstant.java#L161C27-L161C27),
we can see that "rethrow" is false and no NoSuchElementException is
thrown
(https://github.com/openjdk/leyden/blob/b9219784cc277417dc112a7fbf652bdc021cf806/src/java.base/share/classes/jdk/internal/constant/AbstractComputedConstant.java#L183-L186).
I think the "@throws NoSuchElementException" should be removed from
ComputedConstant#orElse
(https://github.com/openjdk/leyden/blob/b9219784cc277417dc112a7fbf652bdc021cf806/src/java.base/share/classes/java/lang/ComputedConstant.java#L294C19-L294C19)
Yours,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4490 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20230804/5ee4b746/smime.p7s>
More information about the core-libs-dev
mailing list