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

Throwable.toString() calls getLocalizedMessage(), but doc says getMessage()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.2, 1.3.0, 5.0
    • core-libs
    • generic, x86
    • generic, windows_nt, windows_xp

      12/13/99 eval1127@eng -- user is actually lobbying for us to change the CODE
      (not the doc) back to getMessage(), vs. getLocalizedMessage(). Need to get
      the justification for this, since we'd previously made a conscious change
      TO getLocalizedMessage() as the result of bug #4059406.


      Name: krT82822 Date: 12/12/99


      original synopsis: "Throwable.toString() behavior different from documentation"

      [this was reported against 1.2.2, but the kestrel-beta docs still mention getMessage() vs. getLocalizedMessage()
      (see also 4059406, where we specifically switched to getLocalizedMessage() as of 1.2beta3)

      java version "1.2.2" (and kestrel-beta)
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      Code segment copied from Throwable.java:
          /**
           * Returns a short description of this throwable object.
           * If this <code>Throwable</code> object was
           * {@link #Throwable(String) created} with an error message string,
           * then the result is the concatenation of three strings:
           * <ul>
           * <li>The name of the actual class of this object
           * <li>": " (a colon and a space)
           * <li>The result of the {@link #getMessage} method for this object
           * </ul>
           * If this <code>Throwable</code> object was {@link #Throwable() created}
           * with no error message string, then the name of the actual class of
           * this object is returned.
           *
           * @return a string representation of this <code>Throwable</code>.
           */
          public String toString() {
          String s = getClass().getName();
          String message = getLocalizedMessage();
          return (message != null) ? (s + ": " + message) : s;
          }

      The JavaDoc comments indicate getMessage() is used, but the code shows
      getLocalizedMessage() is actually used. The code should be corrected to match
      the documentation. This is important since the printStackTrace() methods use
      the getMessage() value as its first line. It would not be good for the first
      line of the stack trace to be localized.
      (Review ID: 98865)
      ======================================================================
      Additional information from user:
      A stack trace is not something you would generally show directly to a user.
      More than likely, the application would display a localized error message to
      the user while the stack trace would get written to an exception log of some
      sort. At least that's how we are doing things. Therefore, the
      printStackTrace method should use the getMessage() method so it is in the
      same language as the trace. The stack trace would be used by a support
      organization to help track down problems for resolution be development.
      Application users have no need for, nor would they want the stack trace,
      therefore there is no need to localize a piece of it.
      sheri.good@Eng 2000-05-12

            psoper Pete Soper (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: