how to retransform a class at runtime

Short Answer Don’t iterate through all the loaded classes from Instrumentation. Instead, just examine the class name passed in to the transformer and if it matches your target class, then transform it. Otherwise, simply return the passed classfileBuffer unmodified. Make the set up calls outside the transformer, (i.e. in your case, do the following from … Read more

Self-invocation behaviour in @Configuration vs. @Component classes

Regular Spring @Components For an explanation of how normal Spring (AOP) proxies or dynamic proxies (JDK, CGLIB) in general work, see my other answer with illustrative sample code. Read that first and you will understand why self-invocation cannot be intercepted for these types of proxies via Spring AOP. @Configuration classes As for @Configuration classes, they … Read more

java.lang.ExceptionInInitializerError with Java-16 | j.l.ClassFormatError accessible: module java.base does not “opens java.lang” to unnamed module

Since JDK 16, the default for the –illegal-access option is deny, so “deep reflection” to JDK classes fails. You can override the behavior by specifying –illegal-access=permit, but you have to be aware of JEP 403: Strongly Encapsulate JDK Internals which is about closing that possibility in a future version, so this option is only a temporary … Read more