On Fri, 19 Jun 2026 07:45:28 GMT, Jaikiran Pai <[email protected]> wrote:
>> 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.
> 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 see that this same question had come up when the change was originally
introduced in valhalla
https://github.com/openjdk/valhalla/pull/1316/changes#r1887168065. I don't know
if that question led to some decision on intentionally choosing
`IllegalMonitorStateException`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/31123#discussion_r3449386060