<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=iso-8859-1">
<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:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#467886;
        text-decoration:underline;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#467886" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">FYI: For tracking I've created
<a href="https://bugs.openjdk.org/browse/JDK-8331317">https://bugs.openjdk.org/browse/JDK-8331317</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><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 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">Brian Goetz <brian.goetz@oracle.com><br>
<b>Date: </b>Monday, 29 April 2024 at 13:54<br>
<b>To: </b>Adam Sotona <adam.sotona@oracle.com>, Øystein Myhre Andersen <o.myhre@gmail.com>, classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Re: Got: IllegalArgumentException: Could not resolve class<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:13.5pt;font-family:"Courier New"">In addition, we should look into making the error mode more obvious; an IAE like this one looks very much like an internal bug.  It would be good if the
 exception was (a) a more specific type of exception, and (b) had more detail of the sort "I needed class hierarchy information for X but it wasn't provided."</span><o:p></o:p></p>
<div>
<p class="MsoNormal">On 4/29/2024 3:54 AM, Adam Sotona wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Your compiler reached the complexity where you reference generated classes from other generated classes.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Class-File API in certain circumstances needs to know some information about the classes referenced from the generated bytecode.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Such information is provided in
<a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/classfile/ClassHierarchyResolver.ClassHierarchyInfo.html">
ClassHierarchyInfo</a> using functional interface <a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/classfile/ClassHierarchyResolver.html">
ClassHierarchyResolver</a>.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">By <a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/classfile/ClassHierarchyResolver.html#defaultResolver()">
default</a> is the information obtained from system class loader. However, the classes you generate are probably not yet known to the system class loader.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">You should specify a custom <a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/classfile/ClassHierarchyResolver.html">
ClassHierarchyResolver</a> for your compiler as a Class-File API option `ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(...))`.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Here you have multiple options how to provide the missing information using combinations of ClassHierarchyResolver factory methods and custom code:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">For example, if the required classes have been already generated and you can provide a physical access to them, you can compose the ClassHierarchyResolver this way:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">`ClassHierarchyResolver.defaultResolver().orElse(ClassHierarchyResolver.</span>
<span style="font-size:11.0pt">ofResourceParsing(Function<ClassDesc, InputStream>).cached())`</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Or if you know all the generated classes in advance, you can provide the missing info about the generated classes in a set and map form:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">`ClassHierarchyResolver.defaultResolver().orElse(ClassHierarchyResolver.</span>
<span style="font-size:11.0pt">of(Collection<ClassDesc> interfaces, Map<ClassDesc, ClassDesc> classToSuperClass))`
</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Or in a form of dynamic direct implementation of the ClassHierarchyResolver:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">`ClassHierarchyResolver.defaultResolver().orElse(classDesc -> isInterface ? : ClassHierarchyInfo.ofInterface() : ClassHierarchyInfo.ofClass(ClassDesc superClass))`</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">classfile-api-dev <a href="mailto:classfile-api-dev-retn@openjdk.org">
<classfile-api-dev-retn@openjdk.org></a> on behalf of Øystein Myhre Andersen <a href="mailto:o.myhre@gmail.com">
<o.myhre@gmail.com></a><br>
<b>Date: </b>Sunday, 28 April 2024 at 12:53<br>
<b>To: </b><a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a>
<a href="mailto:classfile-api-dev@openjdk.org"><classfile-api-dev@openjdk.org></a><br>
<b>Subject: </b>Got: IllegalArgumentException: Could not resolve class</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I'm writing a compiler for Simula (the very first oo language).<br>
Simula is block-oriented with nested blocks and each block is compiled into a classFile.<br>
At a certain level in the hierarchy I get an exception at the end of the classfile building.<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Exception in thread "main" java.lang.IllegalArgumentException:<br>
             Could not resolve class adHoc000_adHoc000_PBLK39_Floor_activateIdleLift<br>
<br>
<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>