Class MyClassLoader
java.lang.Object
java.lang.ClassLoader
com.fasterxml.jackson.module.afterburner.util.MyClassLoader
Class loader that is needed to load generated classes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final boolean
Flag that determines if we should first try to load new class using parent class loader or not; this may be done to try to force access to protected/package-access properties.private static final ConcurrentHashMap
<String, Object> private static final Charset
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canAddClassInPackageOf
(Class<?> cls) Helper method called to check whether it is acceptable to create a new class in package that given class is part of.(package private) Class
<?> defineClassOnParent
(ClassLoader parentClassLoader, String className, byte[] byteCode, int offset, int length) private Class
<?> findLoadedClassOnParent
(ClassLoader parentClassLoader, String className) private Object
getParentClassLoadingLock
(ClassLoader parentClassLoader, String className) Get the class loading lock for the parent class loader for loading the named class.Class
<?> loadAndResolve
(ClassName className, byte[] byteCode) private Class
<?> loadAndResolveUsingParentClassloader
(ClassName className, byte[] byteCode) Attempt to load (and resolve) the class using the parent class loader (if it is configured and present).static int
replaceName
(byte[] byteCode, String from, String to) private void
resolveClassOnParent
(ClassLoader parentClassLoader, Class<?> clazz) Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
UTF8
-
parentParallelLockMap
-
_cfgUseParentLoader
protected final boolean _cfgUseParentLoaderFlag that determines if we should first try to load new class using parent class loader or not; this may be done to try to force access to protected/package-access properties.
-
-
Constructor Details
-
MyClassLoader
-
-
Method Details
-
canAddClassInPackageOf
Helper method called to check whether it is acceptable to create a new class in package that given class is part of. This is used to prevent certain class of failures, related to access limitations: for example, we can not add classes in sealed packages, or core Java packages (java.*).- Since:
- 2.2.1
-
loadAndResolve
public Class<?> loadAndResolve(ClassName className, byte[] byteCode) throws IllegalArgumentException - Parameters:
className
- Interface or abstract class that class to load should extend or implement- Throws:
IllegalArgumentException
-
loadAndResolveUsingParentClassloader
Attempt to load (and resolve) the class using the parent class loader (if it is configured and present). This method will returnnull
if the parent classloader is not configured or cannot be retrieved.- Parameters:
className
- Interface or abstract class that class to load should extend or implementbyteCode
- the generated bytecode for the class to load- Returns:
- the loaded class, or
null
if the class could not be loaded on the parent classloader.
-
getParentClassLoadingLock
Get the class loading lock for the parent class loader for loading the named class. This is effectively the same implementation as ClassLoader#getClassLoadingLock, but using our static parentParallelLockMap and keying off of the parent ClassLoader instance as well as the class name to load.- Parameters:
parentClassLoader
- The parent ClassLoaderclassName
- The name of the to-be-loaded class
-
findLoadedClassOnParent
-
defineClassOnParent
Class<?> defineClassOnParent(ClassLoader parentClassLoader, String className, byte[] byteCode, int offset, int length) -
resolveClassOnParent
-
replaceName
-