I got Exception: Could not resolve class

Øystein Myhre Andersen o.myhre at gmail.com
Sat Oct 19 06:04:02 UTC 2024


I think I can solve the problem with a 're-try loop'.
Something like this:

boolean done = false;

while(! done) {

try {

byte[] bytes =
ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(ClassHierarchy.getResolver())).build(CD_ThisClass,


...

done = true;

return(bytes);

} catch(Throwable e) {}

}

On Sat, Oct 19, 2024 at 7:44 AM Øystein Myhre Andersen <o.myhre at gmail.com>
wrote:

> I tried to implement 'ClassHierarchyInfo' but I got "Sealed type
> ClassHierarchyInfo cannot be super type
> of MyClassHierarchyInfo as it is from a different package or split package
> or module"
>
>
> I misses a method to instantiate 'ClassHierarchyInfo' to deliver the
> result from 'getClassInfo'
>
>
> May be you should add a method like:
>
>
> 'static ClassHierarchyInfo of(ClassDesc subClass, ClassDesc superClass,
> boolean isInterface)'
>
>
> to the 'ClassHierarchyInfo'
>
>
> - Øystein
>
> On Fri, Oct 18, 2024 at 3:46 PM Chen Liang <chen.l.liang at oracle.com>
> wrote:
>
>> 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)
>>
>> I recommend you return a ClassHierarchyResolver implementation of your
>> own, that returns the real-time results from your ClassHierarchy static
>> fields.
>>
>> Regards, Chen
>> ------------------------------
>> *From:* classfile-api-dev <classfile-api-dev-retn at openjdk.org> on behalf
>> of Øystein Myhre Andersen <o.myhre at gmail.com>
>> *Sent:* Friday, October 18, 2024 3:02 AM
>> *To:* Chen Liang <liangchenblue at gmail.com>
>> *Cc:* classfile-api-dev <classfile-api-dev at openjdk.org>
>> *Subject:* Re: I got Exception: Could not resolve class
>>
>> Here is the link:
>>
>> https://github.com/portablesimula/SimulaCompiler2/blob/main/Simula/src/simula/compiler/utilities/ClassHierarchy.java
>>
>> I use:
>> openjdk version "24-ea" 2025-03-18
>> OpenJDK Runtime Environment (build 24-ea+16-1800)
>> OpenJDK 64-Bit Server VM (build 24-ea+16-1800, mixed mode, sharing)
>>
>> - Øystein
>>
>> On Fri, Oct 18, 2024 at 9:51 AM Chen Liang <liangchenblue at gmail.com>
>> wrote:
>>
>> 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.
>>
>> Chen
>>
>> On Fri, Oct 18, 2024 at 2:40 AM Øystein Myhre Andersen <o.myhre at gmail.com>
>> wrote:
>>
>> Below is a snippet of my code:
>>
>>
>> public byte[] buildClassFile() {
>>
>> ClassDesc CD_ThisClass = currentClassDesc();
>>
>> ClassDesc CD_SuperClass = superClassDesc();
>>
>> ClassHierarchy.addClassToSuperClass(CD_ThisClass, CD_SuperClass);
>>
>> try {
>>
>> byte[] bytes =
>> ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(ClassHierarchy.getResolver())).build(CD_ThisClass,
>>
>>
>> ...
>>
>> return(bytes);
>>
>> } catch(Throwable e) {
>>
>> ClassHierarchyResolver resolver = ClassHierarchy.getResolver();
>>
>> ClassDesc desc = ClassDesc.of("simulaFEC.CLASS_CHECKER1_semchecker1_exp
>> ");
>>
>> System.out.println("classInfo("+desc+") = " + resolver.getClassInfo(desc
>> ));
>>
>>
>> e.printStackTrace();
>>
>> return null;
>>
>> }
>>
>> }
>>
>> When I run this code I get:
>>
>>
>> classInfo(ClassDesc[CLASS_CHECKER1_semchecker1_exp]) =
>> ClassHierarchyInfoImpl[superClass=ClassDesc[RTS_CLASS], isInterface=false]
>>
>> java.lang.IllegalArgumentException: Could not resolve class
>> CLASS_CHECKER1_semchecker1_exp
>>
>> at
>> java.base/jdk.internal.classfile.impl.ClassHierarchyImpl.resolve(ClassHierarchyImpl.java:76)
>>
>> at
>> java.base/jdk.internal.classfile.impl.ClassHierarchyImpl.isInterface(ClassHierarchyImpl.java:86)
>>
>> at
>> java.base/jdk.internal.classfile.impl.StackMapGenerator$Type.mergeReferenceFrom(StackMapGenerator.java:1334)
>>
>> .....
>>
>> I use my own 'resolver' which answers that 'CLASS_CHECKER1_semchecker1_
>> exp' is a subclass of 'RTS_CLASS'.
>>
>> I don't understand this.
>>
>>
>> - Øystein Myhre Andersen
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20241019/00c6d666/attachment.htm>


More information about the classfile-api-dev mailing list