-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
b03
-
x86
-
linux
-
Not verified
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());
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());
- relates to
-
JDK-6507802 (reflect) Class.asSubclass throws uninformative CCE
-
- Open
-
-
JDK-6586569 Class.cast exception detail construction should be refactored
-
- Closed
-
-
JDK-6587525 ClassCastException needs "origin" and "target" attributes
-
- Closed
-