<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for sharing Oystein. The problem is that ClassHierarchyResolver.of(Collection, Map) takes the immediate values in the argument and ignores subsequent updates, which is how most ClassFile APIs work, unfortunately. (The same thing happens if you try to
do so for AnnotationValue.OfArray or RuntimeVisibleAnnotationsAttribute)</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I recommend you return a <code>ClassHierarchyResolver</code> implementation of your own, that returns the real-time results from your ClassHierarchy static fields.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards, Chen</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of Øystein Myhre Andersen <o.myhre@gmail.com><br>
<b>Sent:</b> Friday, October 18, 2024 3:02 AM<br>
<b>To:</b> Chen Liang <liangchenblue@gmail.com><br>
<b>Cc:</b> classfile-api-dev <classfile-api-dev@openjdk.org><br>
<b>Subject:</b> Re: I got Exception: Could not resolve class</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>Here is the link:<br>
</div>
<a href="https://github.com/portablesimula/SimulaCompiler2/blob/main/Simula/src/simula/compiler/utilities/ClassHierarchy.java" target="_blank">https://github.com/portablesimula/SimulaCompiler2/blob/main/Simula/src/simula/compiler/utilities/ClassHierarchy.java</a><br>
<div><br>
</div>
<div>I use:</div>
<div>openjdk version "24-ea" 2025-03-18<br>
OpenJDK Runtime Environment (build 24-ea+16-1800)<br>
OpenJDK 64-Bit Server VM (build 24-ea+16-1800, mixed mode, sharing)<br>
</div>
<div><br>
</div>
<div>- Øystein</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Fri, Oct 18, 2024 at 9:51 AM Chen Liang <<a href="mailto:liangchenblue@gmail.com" target="_blank">liangchenblue@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">Hi Øystein, can you share a link to your ClassHierarchy code? ClassFile API has a layer of caching for the ClassHierarchyResolver it uses, which can lead to it not updating to the latest information in your ClassHierarchy.
<div><br>
</div>
<div>Chen</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Fri, Oct 18, 2024 at 2:40 AM Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com" target="_blank">o.myhre@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="padding:0px 0px 0px 2px">
<div style="color:rgb(0,0,0); font-family:Consolas; font-size:10pt; white-space:pre-wrap">
<p style="margin:0px">Below is a snippet of my code:</p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">public byte[] buildClassFile() {</p>
<p style="margin:0px">ClassDesc CD_ThisClass = currentClassDesc();</p>
<p style="margin:0px">ClassDesc CD_SuperClass = superClassDesc();</p>
<p style="margin:0px">ClassHierarchy.addClassToSuperClass(CD_ThisClass, CD_SuperClass);</p>
<p style="margin:0px">try {</p>
<p style="margin:0px">byte[] bytes = ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(ClassHierarchy.getResolver())).build(CD_ThisClass,</p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">...</p>
<p style="margin:0px"></p>
<p style="margin:0px">return(bytes);</p>
<p style="margin:0px">} catch(Throwable e) {</p>
<p style="margin:0px">ClassHierarchyResolver resolver = ClassHierarchy.getResolver();</p>
<p style="margin:0px"></p>
<p style="margin:0px">ClassDesc <span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">
desc</span> = ClassDesc.of("simulaFEC.CLASS_CHECKER1_semchecker1_<span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">exp</span>");</p>
<p style="margin:0px">System.out.println("classInfo("+<span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">desc</span>+") = " + resolver.getClassInfo(<span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">desc</span>));</p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">e.printStackTrace();</p>
<p style="margin:0px">return null;</p>
<p style="margin:0px">}</p>
<p style="margin:0px">}</p>
<p style="margin:0px"></p>
<p style="margin:0px">When I run this code I get:</p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">classInfo(ClassDesc[CLASS_CHECKER1_semchecker1_<span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">exp</span>]) = ClassHierarchyInfoImpl[superClass=ClassDesc[RTS_CLASS], isInterface=false]</p>
<p style="margin:0px">java.lang.IllegalArgumentException: Could not resolve class CLASS_CHECKER1_semchecker1_<span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">exp</span></p>
<p style="margin:0px">at java.base/jdk.internal.classfile.impl.ClassHierarchyImpl.resolve(ClassHierarchyImpl.java:76)</p>
<p style="margin:0px">at java.base/jdk.internal.classfile.impl.ClassHierarchyImpl.isInterface(ClassHierarchyImpl.java:86)</p>
<p style="margin:0px">at java.base/jdk.internal.classfile.impl.StackMapGenerator$Type.mergeReferenceFrom(StackMapGenerator.java:1334)</p>
<p style="margin:0px">.....</p>
<p style="margin:0px"></p>
<p style="margin:0px"></p>
<p style="margin:0px">I use my own 'resolver' which answers that 'CLASS_CHECKER1_semchecker1_<span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">exp</span>' is a subclass of 'RTS_CLASS'.</p>
<p style="margin:0px">I don't understand this.</p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">- <span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">
Øystein</span> <span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">
Myhre</span> <span style="text-decoration-line:underline; text-decoration-style:wavy; text-decoration-color:rgb(255,128,64)">
Andersen</span></p>
<p style="margin:0px"></p>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</body>
</html>