Java Question

Byte Buddy - Handling cyclic references in generated classes

I'm trying to generate runtime wrappers around classes in some class graph, but I don't know how to handle the situation when there is a cycle in the graph.
Imagine there's a class A that has a field of type B, but type B has a field of type A. I want to generate classes A' and B' so that class A' has a field of type B' and B' has a field of type A'.
In Byte Buddy the method "defineField" can receive a parameter of type TypeDefinition. I think there must be a way to define TypeDefinition for a type that isn't defined yet, but I cannot find it yet.


You can define such a field with FieldDescription.Latent but this is at your own risk. Byte Buddy treats this as a specific, unvalidated use case as type redefinition is quite complex considering the interdepencdency.

This said, you can do this without any problems but you can experience VerifierErrors what is something that you are normally promised to not experience.