RFR: 8204955: Extend ClassCastException message

Lois Foltan lois.foltan at oracle.com
Thu Jun 14 20:45:30 UTC 2018


On 6/14/2018 3:41 AM, René Schünemann wrote:

> Hi,
>
> can I please get a review for the following change:
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8204955
> Webrev: http://cr.openjdk.java.net/~simonis/webrevs/2018/8204955
>
> This change adds additional details to the ClassCastException message
> when the class cast failed due to non-matching class loaders.
>
> Example:
>
> "MyLoader/m/MyClass cannot be cast to OtherLoader/m/MyClass. Loaded by
> OtherLoader, but needed class loader MyLoader."
>
> It is now also checked whether the target class is an extended
> interface or super class of the caster class and casting failed due to
> non-matching class loaders.
>
> Example:
>
> "MyLoader/m/MyClass cannot be cast to OtherLoader/m/MyInterface. Found
> matching interface OtherLoader/m/MyInterface loaded by OtherLoader but
> needed class loader MyLoader."
>
> I have added the test
> "jdk/test/hotspot/jtreg/runtime/exceptionMsgs/ClassCastException/ClassCastExceptionTest.java"
> for the new exception message.
>
>
> Thank you,
> Rene
Hi Rene,

Thank you for your work to improve ClassCastException.  I do have some 
concerns about this change:

- In runtime/sharedRuntime.cpp - please do not add another method to 
obtain the class loader's name.  Work is underway to consolidate how 
within the VM a class loader's name is obtained.  See the work for 
JDK-8202605, currently out for review and can be followed at 
http://mail.openjdk.java.net/pipermail/hotspot-dev/2018-June/033063.html

- Work is also underway to standardize the output of certain error 
messages like IllegalAccessError, ClassCastException, etc.  Please see 
the current proposal at 
http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2018-June/028425.html. 
The error changes you have made do not follow this proposed format.

- I'm not sure the added verbiage to ClassCastException is helpful. I 
actually find "Loaded by OtherLoader, but needed class loader MyLoader." 
quite confusing.  How does this help diagnose the issue that caused the 
ClassCastException?

- It is not clear what tests you have run for this change.  This 
information should be included in any RFR request.

Thank you,
Lois




More information about the hotspot-dev mailing list