On Mon, 15 Jun 2026 17:35:32 GMT, Jaikiran Pai <[email protected]> wrote:

>> Several places in the API specifications, specify that:
>> 
>>> Use of value class instances for synchronization, mutexes, or with
>>> {@linkplain java.lang.ref.Reference object references} results in
>>> {@link IdentityException}
>> 
>> whereas here, in these wait(), notify() etc... APIs, which are closer to 
>> synchronization semantics, a `IllegalMonitorStateException` gets thrown for 
>> value objects. Is there a reason why we don't throw a `IdentityException` 
>> from these APIs too? I haven't followed Valhalla development, so if this was 
>> already discussed, please point me to it.
>
> While at it, I did a quick experiment with value object:
> 
> 
> jshell> Object o = Integer.parseInt("42")
> o ==> 42
> 
> jshell> o.wait()
> |  Exception java.lang.IllegalMonitorStateException: java.lang.Integer
> |        at Object.wait0 (Native Method)
> |        at Object.wait (Object.java:433)
> |        at Object.wait (Object.java:387)
> |        at (#15:1)
> 
> 
> So the `IllegalMonitorStateException` thrown merely states the class name of 
> the object but doesn't tell anything more. Whereas for a identity object 
> (like a String), it throws:
> 
> 
> jshell> Object s = new String("")
> s ==> ""
> 
> jshell> s.wait()
> |  Exception java.lang.IllegalMonitorStateException: current thread is not 
> owner
> |        at Object.wait0 (Native Method)
> |        at Object.wait (Object.java:433)
> |        at Object.wait (Object.java:387)
> |        at (#17:1)
> 
> is a bit more informative why it's an illegal monitor state.
> 
> Could the IllegalMonitorStateException exception message for value objects be 
> improved to state something like:
> 
> 
> Exception java.lang.IllegalMonitorStateException: instance of 
> java.lang.Integer value class

I've created https://bugs.openjdk.org/browse/JDK-8386963 to track this.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31123#discussion_r3441022291

Reply via email to