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

java.lang.classfile.CodeBuilder.CatchBuilder should not throw IllegalArgumentException for representable exception handlers

XMLWordPrintable

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

      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();
                                          });
                              }

      --------------------------

      CatchBuilder is intended to construct exception handlers together with code blocks in a CodeBuilder. Currently, it has arbitrary IAE throwing behavior when it detects duplicate blocks catching the same exception, which means the latter blocks are ignored by JVMS. However, such ignorance of duplicate blocks also happen with supertype entries occuring before subtype ones. So such checks are costly and not sound, and it's better for us to just remove them completely.

            liach Chen Liang
            lkuskov Leonid Kuskov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: