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

Class.cast exception detail construction should be refactored

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 7
    • core-libs
    • b18
    • generic
    • generic
    • Not verified

      Experience has shown that refactoring complex exception detail message
      constructions to a separate method tends to improve performance
      with JDK's runtime compilers.

      --- /u/martin/ws/dolphin/src/share/classes/java/lang/Class.java 2007-06-28 14:57:58.260063000 -0700
      +++ /u/martin/ws/checked/src/share/classes/java/lang/Class.java 2007-07-26 16:55:10.570075000 -0700
      @@ -3005,11 +3005,14 @@
            */
           public T cast(Object obj) {
        if (obj != null && !isInstance(obj))
      - throw new ClassCastException("Cannot cast " + obj.getClass().getName()
      - + " to " + getName());
      + throw new ClassCastException(cannotCastMsg(obj));
        return (T) obj;
           }
       
      + private String cannotCastMsg(Object obj) {
      + return "Cannot cast " + obj.getClass().getName() + " to " + getName();
      + }
      +
           /**
            * Casts this {@code Class} object to represent a subclass of the class
            * represented by the specified class object. Checks that that the cast

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: