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

Please add a nested throwable constructor to AssertionError

XMLWordPrintable

    • b100
    • x86
    • linux
    • Not verified

      A DESCRIPTION OF THE REQUEST :
      AssertionError does not have constructors that takes message and a nested throwable. Please add one.

      public AssertionError(String message,Throwable cause) { ...}

      JUSTIFICATION :
      I frequently see code that catches a checked exception that should never be thrown. Sometimes it asserts false, sometimes it throws a RuntimeException, sometimes I'll see an empty catch block, maybe with a comment.

      The right thing to do is to throw an AssertionError.

      catch(ImpossibleException ie) {
          throw new AssertionError("Flow of control should never throw this exception because blah blah blah.",ie);
      }

      It's a pretty minor request; AssertionError does have an initCause() method that works fine. Developers rarely take that extra simple step to use initCause(). However, they do use the two-argument constructor in many other places. One was surprised not to find it when I pointed out initCause().

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I'd like to see a new constructor added to AssertionError. Other developers would use that without blinking.
      ACTUAL -
      The constructor isn't there, so I use initCause. Other developers are astonished when I suggest it.

      CUSTOMER SUBMITTED WORKAROUND :
      intiCause() works fine for me. Not for others.

            darcy Joe Darcy
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: