Unsafe has a method to ensure that classes are initialized:
Unsafe.ensureClassInitialized(Class) line: not available [native method]
I suspect that this type of initialization doesn't lock on the class like regular java class-loading because I've occasionally bumped into some impossible situations. I can give more details later if needed, but does anyone know if class-loading using Unsafe has quirks like that?
Btw, here's a short stack trace of how that class gets loaded up:
Unsafe.ensureClassInitialized(Class) line: not available [native method]
UnsafeFieldAccessorFactory.newFieldAccessor(Field, boolean) line: 25
ReflectionFactory.newFieldAccessor(Field, boolean) line: 122
Field.acquireFieldAccessor(boolean) line: 918
Field.getFieldAccessor(Object) line: 899
Field.get(Object) line: 358
For reference and web seaches, it turns out that you can force class initialization without using Unsafe
:
Class.forName(cls.getName(), true, cls.getClassLoader());
Not pretty, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With