<div dir="ltr">I filed it here: <a href="https://bugs.openjdk.org/browse/JDK-8338661">https://bugs.openjdk.org/browse/JDK-8338661</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Di., 20. Aug. 2024 um 11:32 Uhr schrieb Adam Sotona <<a href="mailto:adam.sotona@oracle.com">adam.sotona@oracle.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg8246799981828914711">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_7173443383493005449WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">Hello,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">There is a problem in StackCounter calculation of maxLocals in combination with custom StackMapTableAttribute covering “dead code”.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Feel free to report it as a bug or let me know and I’ll fill it.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Thank you,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Adam<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<div id="m_7173443383493005449mail-editor-reference-message-container">
<div>
<div>
<div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(181,196,223) currentcolor currentcolor;padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="color:black">From:
</span></b><span style="color:black">classfile-api-dev <<a href="mailto:classfile-api-dev-retn@openjdk.org" target="_blank">classfile-api-dev-retn@openjdk.org</a>> on behalf of Rafael Winterhalter <<a href="mailto:rafael.wth@gmail.com" target="_blank">rafael.wth@gmail.com</a>><br>
<b>Date: </b>Monday, 19 August 2024 at 22:23<br>
<b>To: </b>classfile-api-dev <<a href="mailto:classfile-api-dev@openjdk.org" target="_blank">classfile-api-dev@openjdk.org</a>><br>
<b>Subject: </b>StackMapTable format error: bad type array size in method<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal">Hello,</p>
</div>
<div>
<p class="MsoNormal">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:</p>
</div>
<div>
<div>
<pre style="background:rgb(30,31,34)"><span style="color:rgb(188,190,196)"><br> ClassFile classFile = ClassFile.<i>of</i>(ClassFile.StackMapsOption.</span><i><span style="color:rgb(199,125,187)">DROP_STACK_MAPS</span></i><span style="color:rgb(188,190,196)">);<br> </span><span style="color:rgb(207,142,109)">byte</span><span style="color:rgb(188,190,196)">[] bytes = classFile.build(ClassDesc.<i>of</i>(</span><span style="color:rgb(106,171,115)">"foo.Bar"</span><span style="color:rgb(188,190,196)">), classBuilder -> classBuilder.withMethod(<br> </span><span style="color:rgb(106,171,115)">"foo"</span><span style="color:rgb(188,190,196)">,<br> MethodTypeDesc.<i>ofDescriptor</i>(</span><span style="color:rgb(106,171,115)">"()J"</span><span style="color:rgb(188,190,196)">),<br> </span><span style="color:rgb(42,172,184)">0</span><span style="color:rgb(188,190,196)">,<br> methodBuilder -> {<br> methodBuilder.withCode(codeBuilder -> {<br> codeBuilder.new_(ClassDesc.<i>of</i>(RuntimeException.</span><span style="color:rgb(207,142,109)">class</span><span style="color:rgb(188,190,196)">.getName()));<br> codeBuilder.dup();<br> codeBuilder.invokespecial(ClassDesc.<i>of</i>(RuntimeException.</span><span style="color:rgb(207,142,109)">class</span><span style="color:rgb(188,190,196)">.getName()),<br> </span><span style="color:rgb(106,171,115)">"<init>"</span><span style="color:rgb(188,190,196)">,<br> MethodTypeDesc.<i>ofDescriptor</i>(</span><span style="color:rgb(106,171,115)">"()V"</span><span style="color:rgb(188,190,196)">));<br> codeBuilder.athrow();<br> Label f2 = codeBuilder.newBoundLabel();<br> codeBuilder.lstore(</span><span style="color:rgb(42,172,184)">1</span><span style="color:rgb(188,190,196)">);<br> Label f3 = codeBuilder.newBoundLabel();<br> codeBuilder.lload(</span><span style="color:rgb(42,172,184)">1</span><span style="color:rgb(188,190,196)">);<br> codeBuilder.lreturn();<br> codeBuilder.with(StackMapTableAttribute.<i>of</i>(List.<i>of</i>(<br> StackMapFrameInfo.<i>of</i>(f2,<br> List.<i>of</i>(StackMapFrameInfo.ObjectVerificationTypeInfo.<i>of</i>(ClassDesc.<i>of</i>(</span><span style="color:rgb(106,171,115)">"foo.Bar"</span><span style="color:rgb(188,190,196)">))),<br> List.<i>of</i>(StackMapFrameInfo.SimpleVerificationTypeInfo.</span><i><span style="color:rgb(199,125,187)">ITEM_LONG</span></i><span style="color:rgb(188,190,196)">)),<br> StackMapFrameInfo.<i>of</i>(f3,<br> List.<i>of</i>(StackMapFrameInfo.ObjectVerificationTypeInfo.<i>of</i>(ClassDesc.<i>of</i>(</span><span style="color:rgb(106,171,115)">"foo.Bar"</span><span style="color:rgb(188,190,196)">)),<br> StackMapFrameInfo.SimpleVerificationTypeInfo.</span><i><span style="color:rgb(199,125,187)">ITEM_LONG</span></i><span style="color:rgb(188,190,196)">),<br> List.<i>of</i>())<br> )));<br> });<br> }));<br> </span><span style="color:rgb(207,142,109)">new </span><span style="color:rgb(188,190,196)">ClassLoader() {<br> </span><span style="color:rgb(179,174,96)">@Override<br> </span><span style="color:rgb(207,142,109)">protected </span><span style="color:rgb(188,190,196)">Class<?> </span><span style="color:rgb(86,168,245)">findClass</span><span style="color:rgb(188,190,196)">(String name) </span><span style="color:rgb(207,142,109)">throws </span><span style="color:rgb(188,190,196)">ClassNotFoundException {<br> </span><span style="color:rgb(207,142,109)">if </span><span style="color:rgb(188,190,196)">(name.equals(</span><span style="color:rgb(106,171,115)">"foo.Bar"</span><span style="color:rgb(188,190,196)">)) {<br> </span><span style="color:rgb(207,142,109)">return </span><span style="color:rgb(188,190,196)">defineClass(name, </span><span style="color:rgb(199,125,187)">bytes</span><span style="color:rgb(188,190,196)">, </span><span style="color:rgb(42,172,184)">0</span><span style="color:rgb(188,190,196)">, </span><span style="color:rgb(199,125,187)">bytes</span><span style="color:rgb(188,190,196)">.</span><span style="color:rgb(199,125,187)">length</span><span style="color:rgb(188,190,196)">);<br> } </span><span style="color:rgb(207,142,109)">else </span><span style="color:rgb(188,190,196)">{<br> </span><span style="color:rgb(207,142,109)">return super</span><span style="color:rgb(188,190,196)">.findClass(name);<br> }<br> }<br> }.findClass(</span><span style="color:rgb(106,171,115)">"foo.Bar"</span><span style="color:rgb(188,190,196)">).getMethods();<u></u><u></u></span></pre>
</div>
</div>
<div>
<p class="MsoNormal">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?</p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks! Rafael</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div></blockquote></div>