-
Bug
-
Resolution: Fixed
-
P4
-
25
-
None
-
master
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());
}
@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());
}
- links to
-
Commit(master) openjdk/jdk/189017f7
-
Review(master) openjdk/jdk/26255