<p>The problem is in StackMapGenerate.</p><p>The original method name of Frame.CheckStack is misleading as it adds 1 to index.</p><p>The recent changes assume it does not but there are still calls which assume this.</p><p> </p><p>testcode<br>```<br>import module java.base;</p><p>public class MaxStack  {</p><p>   private static void build(CodeBuilder cob) {<br>       cob<br>          .iload(0)<br>          .i2l()<br>          .lreturn();<br>   }<br><br>   public static void main(String[] args) throws IOException {<br>       ClassFile cf = ClassFile.of(ClassFile.StackMapsOption.GENERATE_STACK_MAPS); // MaxStack = 3<br>//        ClassFile cf = ClassFile.of(); // MaxStack = 2<br>       byte[] bytes = cf<br>               .build(ClassDesc.of("TestMaxStack"),<br>           clb -> clb.withFlags(ClassFile.ACC_PUBLIC  | ClassFile.ACC_SUPER)<br>        .withVersion(49,0)<br>               .withMethodBody("Table", MethodTypeDesc.ofDescriptor("(I)J"),<br>                    ClassFile.ACC_STATIC,<br>             MaxStack::build));<br>       cf = ClassFile.of();<br>       ClassModel cm = cf.parse(bytes);<br>       cm.methods().stream()<br>               .flatMap(m -> m.attributes().stream())<br>        .filter(attr -> attr instanceof CodeAttribute)<br>        .map(attr -> ((CodeAttribute)attr).maxStack())<br>        .map(sz -> "MaxStack = " + sz)<br>               .forEach(System.out::println);<br>   }<br>}<br>```<br><br><br> </p><blockquote><p>------ Original Message ------<br>From: rafael.wth@gmail.com<br>To: classfile-api-dev@openjdk.org<br>Sent: Thursday, October 24th 2024, 07:33<br>Subject: Stack size miscalculated with try-catch blocks<br> </p><div dir="ltr"><div>Hello,</div><div> </div><div>when testing a recent build of the JDK with my bridge to ASM, I encountered some test failures. This is related to the stack size of a method being calculated with an additional, unnecessary slot. This can be reproduced using <a target="_blank" rel="noopener noreferrer" href="https://github.com/raphw/asm-jdk-bridge">https://github.com/raphw/asm-jdk-bridge</a></div><div> </div><div>This can also be reproduced by inspecting the computed stack for:</div><div><div style="background-color:rgb(30,31,34);color:rgb(188,190,196);"><pre style="font-family:"JetBrains Mono" , monospace;font-size:9.8pt;"><span style="color:rgb(207,142,109);">void </span><span style="color:rgb(86,168,245);">c</span>() {<br>    <span style="color:rgb(207,142,109);">try </span>{<br>        <span style="color:rgb(207,142,109);">throw new </span>RuntimeException();<br>    } <span style="color:rgb(207,142,109);">catch </span>(RuntimeException e) {<br>    }<br>}</pre></div></div><div>which will be computed as 3 and not 2.</div><div> </div><div>Best regards, Rafael<br> </div></div></blockquote>