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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 26
    • Affects Version/s: 25
    • Component/s: 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());
          }

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

              Created:
              Updated:
              Resolved: