[External] : Re: Got: IllegalArgumentException: Could not resolve class

Øystein Myhre Andersen o.myhre at gmail.com
Mon Apr 29 14:33:10 UTC 2024


Can you inform me if you incorporate this in the next release.

- Øystein

On Mon, Apr 29, 2024 at 4:09 PM Adam Sotona <adam.sotona at oracle.com> wrote:

> It is good point that information about thisClass and superClass should be
> implicitly forwarded to the class hierarchy resolution for thisClass build.
>
>
>
> Thank you,
>
> Adam
>
>
>
> *From: *Øystein Myhre Andersen <o.myhre at gmail.com>
> *Date: *Monday, 29 April 2024 at 15:23
> *To: *liangchenblue at gmail.com <liangchenblue at gmail.com>
> *Cc: *Adam Sotona <adam.sotona at oracle.com>, classfile-api-dev at openjdk.org
> <classfile-api-dev at openjdk.org>
> *Subject: *[External] : Re: Got: IllegalArgumentException: Could not
> resolve class
>
> Proposal:
>
>
>
> I defined a utility class:
>
>
>
> *public* *abstract* *class* ClassHierarchy {
>
> *private* *static* Map<ClassDesc, ClassDesc> *classToSuperClass* = *new*
> HashMap<ClassDesc, ClassDesc>();
>
> *private* *static* Collection<ClassDesc> *interfaces* = *new*
> Vector<ClassDesc>();
>
>
>
> *public* *static* ClassHierarchyResolver getResolver() {
>
> ClassHierarchyResolver res = ClassHierarchyResolver.*defaultResolver*()
>
> .orElse(ClassHierarchyResolver.*of*(*interfaces*, *classToSuperClass*));
>
> *return* res;
>
> }
>
>
>
> *public* *static* *void* addClassToSuperClass(ClassDesc cld, ClassDesc sup)
> {
>
> *classToSuperClass*.put(cld, sup);
>
> }
>
> }
>
>
>
>  And built my class files with a method like:
>
>
>
> *public* *byte*[] buildClassFile() {
>
> ClassDesc CD_ThisClass = ...
>
> ClassDesc CD_SuperClass = ...
>
> ClassHierarchy.*addClassToSuperClass*(CD_ThisClass, CD_SuperClass);
>
> *byte*[] bytes = ClassFile.*of*(ClassFile.ClassHierarchyResolverOption
>
> .*of*(ClassHierarchy.*getResolver*())).build(CD_ThisClass,
>
> classBuilder -> {
>
> classBuilder
>
> .withSuperclass(CD_SuperClass);
>
> ... ...
>
>
>
>
>
> This could perhaps have been done internally  by letting
> .withSuperclass(CD_SuperClass);
>
> make a call ala  ClassHierarchy.*addClassToSuperClass*(CD_ThisClass,
> CD_SuperClass);
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20240429/e90d404d/attachment-0001.htm>


More information about the classfile-api-dev mailing list