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

AssertionError whose "detail message" is Throwable should set cause

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.1
    • 1.4.0
    • core-libs
    • None
    • hopper
    • generic
    • generic
    • Verified

        One common use of assertions is to assert "this line can't be reached" it's not
        uncommon to have constructs such as:

          try {
            doSomething();
          } catch (SomeException se) {
            // can't really get here because doSomething() can't really throw
            // SomeException in this context, despite it's signature.
          }

        To achieve failure capture in an assertion, one would do this:

          try {
            doSomething();
          } catch (SomeException se) {
            assert false : se;
          }

        If the AssertionError has SomeException as its cause, the resulting stack
        trace will be FAR more informative. Note that this is just an API refinement:
        it is consistent with the existing spec.

              jjb Josh Bloch (Inactive)
              jjb Josh Bloch (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: