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

InvalidObjectException should be retrofitted with constructors taking a cause argument

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • None

      java.io.InvalidObjectException defines a single constructor:

      InvalidObjectException(String reason)

      It should be retrofitted for convenient exception chaining by providing these constructors:

      InvalidObjectException(String message)
      InvalidObjectException(String message, Throwable cause)
      InvalidObjectException(Throwable cause)

      A Serializable class may use a single method to check class invariants in both the constructor and the readObject() method. If a developer defines many such classes, all of them will have to repeat the following code in readObject() to avoid loss of information in the case where an invalid instance is deserialized:

      try {
                  checkInvariants();
              } catch (Exception e) {
                  InvalidObjectException x = new InvalidObjectException(
                          e.getMessage());
                  x.initCause(e);
                  throw x;
              }

      The stack trace of a deserialization exception can be particularly unhelpful without the cause of the exception, so InvalidObjectException is a particularly good example of an exception whose usefulness is improved by retrofitting.

            Unassigned Unassigned
            teericks Thomas Erickson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: