<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="en-CZ" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Thank you for reporting it.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">This can be a nice enhancement of the StackCounter error reporting.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Please let me know if you have troubles to
<a href="https://bugs.openjdk.org/secure/CreateIssue!default.jspa">create</a> a new JDK Enhancement issue on
</span><span style="color:#212121">core-libs / java.lang.classfile subcomponent</span><span lang="EN-US" style="color:#212121">.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#212121"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#212121">Thank you,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#212121">Adam</span><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">From:
</span></b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of david32768@btinternet.com david32768@btinternet.com <david32768@btinternet.com><br>
<b>Date: </b>Monday, 29 January 2024 at 7:46<br>
<b>To: </b>classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Duplicate and ambiguous switch cases<o:p></o:p></span></p>
</div>
<div>
<p><o:p> </o:p></p>
<p>I apologise for the misleading comment about the error message.</p>
<p><o:p> </o:p></p>
<p>If the bad lookup is picked up by StackMapGenerate (V65) it also prints the code.</p>
<p>If the bad lookup is picked up by StackCounter (V50) it does not.</p>
<p><o:p> </o:p></p>
<p>```</p>
<p>import java.io.IOException;</p>
<p>import java.lang.constant.ClassDesc;</p>
<p>import java.lang.constant.MethodTypeDesc;</p>
<p>import java.nio.file.Files;</p>
<p>import java.nio.file.Path;</p>
<p>import java.nio.file.Paths;</p>
<p>import java.util.List;</p>
<p>import java.util.ArrayList;</p>
<p><o:p> </o:p></p>
<p>import java.lang.classfile.*;</p>
<p>import java.lang.classfile.instruction.*;</p>
<p><o:p> </o:p></p>
<p>public class CBBuildDup {</p>
<p><o:p> </o:p></p>
<p>private static void build(CodeBuilder cob) {</p>
<p>Label L1 = cob.newLabel();</p>
<p>Label L2 = cob.newLabel();</p>
<p>SwitchCase sc1 = SwitchCase.of(0,L2); // 0 -> L2</p>
<p>SwitchCase sc2 = SwitchCase.of(0,L2); // 0 -> L2 Duplicate</p>
<p>// SwitchCase sc2 = SwitchCase.of(0,L1); // 0 -> L1 Ambiguous</p>
<p>List<SwitchCase> cases = new ArrayList<>();</p>
<p>cases.add(sc1);</p>
<p>cases.add(sc2);</p>
<p>cob.iload(0)</p>
<p>.lookupswitch(L1, cases)</p>
<p>// .tableswitch(L1, cases)</p>
<p>.labelBinding(L2)</p>
<p>.iconst_1()</p>
<p>.ireturn()</p>
<p>.labelBinding(L1)</p>
<p>.iconst_0()</p>
<p>.ireturn();</p>
<p>}</p>
<p>public static void main(String[] args) throws IOException {</p>
<p>byte[] bytes = ClassFile.of()</p>
<p>.build(ClassDesc.of("CBSwitchDup"),</p>
<p>clb -> clb.withFlags(ClassFile.ACC_PUBLIC| ClassFile.ACC_SUPER)</p>
<p>// .withVersion(50,0) // bad lookup (StackCounter)</p>
<p>.withVersion(65,0) // bad lookup + code dump (StackMapGenerator)</p>
<p>.withMethodBody("table", MethodTypeDesc.ofDescriptor("(I)I"),</p>
<p>ClassFile.ACC_PUBLIC | ClassFile.ACC_STATIC, CBBuildDup::build));</p>
<p>for (VerifyError err:ClassFile.of().verify(bytes)) {</p>
<p>System.err.println(err);</p>
<p>}</p>
<p>Path pathc = Paths.get("CBSwitchDup.class");</p>
<p>Files.write(pathc,bytes);</p>
<p>}</p>
<p>}</p>
<p>```</p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>