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

java.lang.classfile.CodeBuilder.catchingAll doesn't throw IllegalArgumentException if an existing catch block catches all exceptions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • 24, 25
    • core-libs
    • None

      The meaning of the assertion
      Throws: IllegalArgumentException if an existing catch block catches all exceptions is ambiguous. The following piece of code can be interpreted as indefinite:
      (Consumer<CodeBuilder.CatchBuilder>) catchBuilder -> {
          catchBuilder.catchingAll(tb -> {
              tb.astore(1);
              tb.iconst_0();
              tb.ireturn();
          });
          catchBuilder.catchingAll(tb -> {
              tb.astore(1);
              tb.iconst_1();
              tb.ireturn();
          });
      };

      Presumably, it should throw an IllegalArgumentException. However, the expected exception is not thrown. Also, no cases were found that could propagate this exception, so the assertion seems superfluous in the specification.

      The following sequence also looks like a candidate to throw an IllegalArgumentException:

      (Consumer<CodeBuilder.CatchBuilder>) catchBuilder -> {
                                  catchBuilder.catchingAll(
                                          tb -> {
                                              tb.astore(1);
                                              tb.iconst_0();
                                              tb.ireturn();
                                          });
                                  catchBuilder.catching( classDescOf(Exception.class),
                                          tb -> {
                                              tb.astore(1);
                                              tb.iconst_1();
                                              tb.ireturn();
                                          });
                              }

            Unassigned Unassigned
            lkuskov Leonid Kuskov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: