JDK-8204955 : Extend ClassCastException message
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 11
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2018-06-13
  • Updated: 2024-11-05
  • Resolved: 2018-06-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11Resolved
Related Reports
Duplicate :  
Description
Add further details to ClassCastException message when casting the class failed because of mismatching class loaders.

Currently the message of the ClassCastException has the following format:
"caster_class cannot be cast to target_class"

This message is sufficient if the caster_class and the target_class are not identical, target_class is no interface implemented by caster_class or target_class is no super class of caster_class.

However the ClassCastException may also be thrown when these requirements are met but the caster_class and the target_class have been loaded by different class loaders.

This enhancement intends to add additional information to the ClassCastException message, when caster_class and target_class have been loaded by different class loaders but otherwise meet all requirements for a class cast.

After JDK-8169559 class cast message now says:
class java.sql.Time cannot be cast to class Derived (java.sql.Time is in module java.sql of loader 'platform'; Derived is in unnamed module of loader 'app')
or 
class p4.c4 cannot be cast to class java.lang.String (p4.c4 is in unnamed module of loader 'MyClassLoader' @<id>; java.lang.String is in module java.base of loader 'bootstrap'

Comments
This issue was solved by JDK-8169559.
28-06-2018