JDK-6456938 : (reflect) Class.cast(Object) throws CCE without detail message
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2006-08-03
  • Updated: 2012-09-28
  • Resolved: 2011-05-18
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 7
7 b03Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
java.lang.Class.cast(Object) (JDK 5 or 6) has

	    throw new ClassCastException();

with no detail message. Regular CCEs seem to give at least the class name of the actual object as a detail message, on the assumption that this is information the programmer does not know and may need in order to debug it. In JDK 6 it seems the expected class name is given too. Class.cast(...) should give at least as much information. The expected type is in fact more important than for a direct cast, since for this method call the identity of the Class object may not be statically known. So would suggest e.g.

throw new ClassCastException(obj.getClass().getName() + " cannot be cast to " + getName());

Comments
EVALUATION Yes.
04-08-2006