I have a scenario where user of my application provides a jar(say,abc.jar) at runtime. In my application I use classes defined in this jar. There is one class in this jar, called CI. This is package protected class in this jar file(say, p1.CI). There is another public class in this jar, Connection, whose one method create object of CI class and return that, but return type of this method is Object and hence I use reference variable of Object class to hold this returned object. So I get the object of class CI stored in the Object type reference variable.
Object obj=connection.getCI();
Now, using this obj and Java reflection, I call various package protected attributes and methods of class CI(setting setAccessbile(true) for field and methods that I want to access). I am migrating my application to Java 17, and doing such manipulation is not allowed. I am trying to use byte buddy to create dynamic class which is subclass of CI, but seems like I am messing up somewhere, especially on field access. I think I am creating new dynamic object every time I access field and hence if I set field by some value, I don’t get that vale back next time I access that same field. Do byte buddy has something like creating dynamic class once and use the same to access fields and methods of CI class or some other approach should be used.