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

Mix and match of dead and valid exception handler leads to malformed class file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 26
    • 25
    • core-libs
    • None

      The code to write exception handlers in DirectCodeBuilder has an incorrect `handlersSize++`, which means a mix and match of dead and valid exception handlers can lead to malformed class files. Verified with a simple test that throws ConstantPoolException:

          @Test
          void testFilterMixedExceptionCatch() {
              var cc = ClassFile.of(ClassFile.DeadLabelsOption.DROP_DEAD_LABELS);
              var code = cc.parse(cc.build(CD_Void, clb ->
                      clb.withMethodBody("m", MTD_void, 0, cob -> {
                          cob.return_();
                          var l = cob.newBoundLabel();
                          cob.pop().return_();
                          cob.exceptionCatch(cob.startLabel(), l, l, Optional.empty());
                          cob.exceptionCatch(cob.newLabel(), l, l, CD_Exception);
                      }))).methods().get(0).code().get();
              assertEquals(1, code.exceptionHandlers().size(), () -> code.exceptionHandlers().toString());
              assertEquals(Optional.empty(), code.exceptionHandlers().getFirst().catchType());
          }

            liach Chen Liang
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: