Bytecode Instrumentation and Class Loading.

Michael Rasmussen Michael.Rasmussen at roguewave.com
Fri Sep 20 12:05:12 UTC 2019


On 9/18/19 2:47 PM, Sam Thomas wrote:
> Hi,
>
> I'm trying to understand if a class will load as soon as all the transformers return. The aim is to get a class reference of a class I have seen in my transformer.

Short answer: no.

Trying to define a class can cause other classes to try to be loaded before (for instance the super types), meaning when you're done transforming class A, the same thread might try to load multiple other classes before it finishes defining A.
And if any of these fail, A will also fail to be defined.

> Also if there is way to get the same without triggering class loading - if the class is not loaded return a null reference.

ClassLoader has a protected method findLoadedClass that checks if a class is loaded by that classloader and returns the Class instance if so, or null otherwise.
But as mentioned, the method is protected so normally not accessible outside the classloader itself.

/Michael


More information about the serviceability-dev mailing list