[lworld] RFR: 8287241: Add IdentityException to report that a value object is not valid [v2]

liach duke at openjdk.java.net
Wed May 25 21:42:08 UTC 2022


On Wed, 25 May 2022 20:36:52 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Add class java.lang.IdentityException, when thrown indicates that an identity object was required but a value object was supplied.
>> 
>> Also add methods `java.util.Objects.requireIdentity(obj)` and `Objects.requireIdentity(obj, message)` to check and throw.
>> 
>> Updated java.lang.ref.Reference and related tests to use new exception and method.
>
> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add Objects.requireIdentity(obj, Supplier<String> supplier);
>   update copyright

src/java.base/share/classes/java/util/Objects.java line 206:

> 204:         Objects.requireNonNull(obj);
> 205:         var cl = obj.getClass();
> 206:         if (cl.isValue())

Just curious, is it that all instances of `Object` (from `new Object()`) are identity, and all other classes that are neither value nor identity are abstract classes?

-------------

PR: https://git.openjdk.java.net/valhalla/pull/696



More information about the valhalla-dev mailing list