Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6456938

(reflect) Class.cast(Object) throws CCE without detail message

XMLWordPrintable

    • 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());

            iris Iris Clark
            jglick Jesse Glick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: