On Tue, 23 Jun 2026 15:21:15 GMT, Viktor Klang <[email protected]> wrote:
>> Infact, should the newly added `@throws` specification state that the
>> `IdentityException` is only thrown when value objects preview is enabled?
>> Furthermore, should the newly introduced:
>>
>>
>> Objects.requireIdentity(obj, "obj");
>>
>> instead be invoked only if `PreviewFeatures.isEnabled()`? I realize that
>> deep within the call of `Objects.requireIdentity`, the preview enabled check
>> does get exercised and this call returns normally when preview is disabled.
>> But it might be more clear here at the call site to use a
>> `PreviewFeatures.isEnabled()` before calling `Objects.requireIdentity()`.
>
> Personal preference is to only have the isEnabled()-check within
> requireIdentity itself, to avoid extraneous code throughout the codebase.
> Infact, should the newly added @throws specification state that the
> IdentityException is only thrown when value objects preview is enabled?
The latest specification in `Objects.hasIdentity()` specifies:
... All objects are identity objects when preview
* features are disabled; consequently, this method behaves the same as
* {@link #nonNull Objects.nonNull} when preview features are disabled.
So I think explicitly mentioning that `IdentityException` gets thrown only when
preview is enabled isn't necessary.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/31123#discussion_r3557680258