<div dir="ltr"><div>Hello,</div><div>when testing some of the corner cases within the unit tests of Byte Buddy, I found some further errors when it comes to dead code and using ClassWriter. All those cases work when using ASM. As a reproducer, consider the following:</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"><br>    ClassFile classFile = ClassFile.<span style="font-style:italic">of</span>(ClassFile.StackMapsOption.<span style="color:rgb(199,125,187);font-style:italic">DROP_STACK_MAPS</span>);<br>    <span style="color:rgb(207,142,109)">byte</span>[] bytes = classFile.build(ClassDesc.<span style="font-style:italic">of</span>(<span style="color:rgb(106,171,115)">"foo.Bar"</span>), classBuilder -> classBuilder.withMethod(<br>            <span style="color:rgb(106,171,115)">"foo"</span>,<br>            MethodTypeDesc.<span style="font-style:italic">ofDescriptor</span>(<span style="color:rgb(106,171,115)">"()J"</span>),<br>            <span style="color:rgb(42,172,184)">0</span>,<br>            methodBuilder -> {<br>                methodBuilder.withCode(codeBuilder -> {<br>                    codeBuilder.new_(ClassDesc.<span style="font-style:italic">of</span>(RuntimeException.<span style="color:rgb(207,142,109)">class</span>.getName()));<br>                    codeBuilder.dup();<br>                    codeBuilder.invokespecial(ClassDesc.<span style="font-style:italic">of</span>(RuntimeException.<span style="color:rgb(207,142,109)">class</span>.getName()),<br>                            <span style="color:rgb(106,171,115)">"<init>"</span>,<br>                            MethodTypeDesc.<span style="font-style:italic">ofDescriptor</span>(<span style="color:rgb(106,171,115)">"()V"</span>));<br>                    codeBuilder.athrow();<br>                    Label f2 = codeBuilder.newBoundLabel();<br>                    codeBuilder.lstore(<span style="color:rgb(42,172,184)">1</span>);<br>                    Label f3 = codeBuilder.newBoundLabel();<br>                    codeBuilder.lload(<span style="color:rgb(42,172,184)">1</span>);<br>                    codeBuilder.lreturn();<br>                    codeBuilder.with(StackMapTableAttribute.<span style="font-style:italic">of</span>(List.<span style="font-style:italic">of</span>(<br>                            StackMapFrameInfo.<span style="font-style:italic">of</span>(f2,<br>                                    List.<span style="font-style:italic">of</span>(StackMapFrameInfo.ObjectVerificationTypeInfo.<span style="font-style:italic">of</span>(ClassDesc.<span style="font-style:italic">of</span>(<span style="color:rgb(106,171,115)">"foo.Bar"</span>))),<br>                                    List.<span style="font-style:italic">of</span>(StackMapFrameInfo.SimpleVerificationTypeInfo.<span style="color:rgb(199,125,187);font-style:italic">ITEM_LONG</span>)),<br>                            StackMapFrameInfo.<span style="font-style:italic">of</span>(f3,<br>                                    List.<span style="font-style:italic">of</span>(StackMapFrameInfo.ObjectVerificationTypeInfo.<span style="font-style:italic">of</span>(ClassDesc.<span style="font-style:italic">of</span>(<span style="color:rgb(106,171,115)">"foo.Bar"</span>)),<br>                                            StackMapFrameInfo.SimpleVerificationTypeInfo.<span style="color:rgb(199,125,187);font-style:italic">ITEM_LONG</span>),<br>                                    List.<span style="font-style:italic">of</span>())<br>                    )));<br>                });<br>            }));<br>    <span style="color:rgb(207,142,109)">new </span>ClassLoader() {<br>        <span style="color:rgb(179,174,96)">@Override<br></span><span style="color:rgb(179,174,96)">        </span><span style="color:rgb(207,142,109)">protected </span>Class<?> <span style="color:rgb(86,168,245)">findClass</span>(String name) <span style="color:rgb(207,142,109)">throws </span>ClassNotFoundException {<br>            <span style="color:rgb(207,142,109)">if </span>(name.equals(<span style="color:rgb(106,171,115)">"foo.Bar"</span>)) {<br>                <span style="color:rgb(207,142,109)">return </span>defineClass(name, <span style="color:rgb(199,125,187)">bytes</span>, <span style="color:rgb(42,172,184)">0</span>, <span style="color:rgb(199,125,187)">bytes</span>.<span style="color:rgb(199,125,187)">length</span>);<br>            } <span style="color:rgb(207,142,109)">else </span>{<br>                <span style="color:rgb(207,142,109)">return super</span>.findClass(name);<br>            }<br>        }<br>    }.findClass(<span style="color:rgb(106,171,115)">"foo.Bar"</span>).getMethods();</pre></div></div><div>It gives a class format error. Java agents sometimes have to process all kinds of strange byte code, so ideally these cases should be supported. Is this a bug in the stack map frame attribute writer?</div><div><br></div><div>Thanks! Rafael<br></div></div>