Define classes with circular dependency?
John Hendrikx
john at int4.org
Sat Mar 15 09:18:48 UTC 2025
Hi list,
I'm trying to use the ClassFile API to automatically implement control
classes (as found in JavaFX). These classes define inner class
CssMetaData implementations that refer back to the outer class, and the
outer class refers to these implementations via static fields. When I
define one of the inner types using Lookup::defineClass I get a
NoClassDefFoundError for the outer type. When I define the outer type
first, I get a NoClassDefFoundError for one of the inner types. The
situation is essentially this:
publicclassSample {
privatefinalProperty b= newProperty(A);
privatestaticfinalCssMetaData A= newCssMetaData() {
@Override
publicProperty getProperty(Object obj) {
return((Sample)obj).b;
}
};
}
abstractclassCssMetaData {
abstractProperty getProperty(Object obj);
}
classProperty {
publicProperty(CssMetaData a) {
}
}
I'm trying to generate the Sample class. The classes CssMetaData and
Propery are pre-existing. As you can see, Sample refers to A in a
property it creates, while A refers to that property by direct field
access after a cast.
Note that the above is perfectly legal as a Java class, and I think the
bytecode I generate is correct. It seems I would need to be able to
define both classes at the same time, but Lookup doesn't seem to have
anything for this purpose.
I'd appreciate any insights!
--John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20250315/42f8b4b8/attachment-0001.htm>
More information about the classfile-api-dev
mailing list