I got Exception: Could not resolve class

Chen Liang liangchenblue at gmail.com
Fri Oct 18 07:51:30 UTC 2024


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/20241018/814deeb4/attachment.htm>


More information about the classfile-api-dev mailing list