public class ClassFileUtils extends Object
ProxyServices.
Also contains logic needed to crack open CL methods should that approach be used - this is invoked from WeldStartup.
In oder to support JDK 9+, this class now uses Unsafe as we need to be able to define classes with different ProtectionDomain
In JDK 12+, even Unsafe fails (no "override" field) hence we fallback to setAccessible() but in this case
integrators should already go through new SPI hence avoiding this problem.| Modifier and Type | Method and Description |
|---|---|
static void |
makeClassLoaderMethodsAccessible()
This method cracks open
ClassLoader#defineClass() methods using Unsafe. |
static Class<?> |
toClass(org.jboss.classfilewriter.ClassFile ct,
Class<?> originalClass,
org.jboss.weld.serialization.spi.ProxyServices proxyServices,
ProtectionDomain domain)
Delegates proxy creation via
ProxyServices to the integrator. |
static Class<?> |
toClass(org.jboss.classfilewriter.ClassFile ct,
ClassLoader loader,
ProtectionDomain domain)
Converts the class to a
java.lang.Class object. |
public static void makeClassLoaderMethodsAccessible()
ClassLoader#defineClass() methods using Unsafe.
It is invoked during WeldStartup#startContainer() and only in case the integrator does not
fully implement ProxyServices.
Method first attempts to use Unsafe and if that fails then reverts to setAccessiblepublic static Class<?> toClass(org.jboss.classfilewriter.ClassFile ct, ClassLoader loader, ProtectionDomain domain)
java.lang.Class object. Once this method is called, further modifications are not
allowed any more.
The class file represented by the given CtClass is loaded by the given class loader to construct a
java.lang.Class object. Since a private method on the class loader is invoked through the reflection API,
the caller must have permissions to do that.
An easy way to obtain ProtectionDomain object is to call getProtectionDomain() in
java.lang.Class. It returns the domain that the class belongs to.
This method is provided for convenience. If you need more complex functionality, you should write your own class loader.loader - the class loader used to load this class. For example, the loader returned by getClassLoader()
can be used for this parameter.domain - the protection domain for the class. If it is null, the default domain created by
java.lang.ClassLoader ispublic static Class<?> toClass(org.jboss.classfilewriter.ClassFile ct, Class<?> originalClass, org.jboss.weld.serialization.spi.ProxyServices proxyServices, ProtectionDomain domain)
ProxyServices to the integrator.Copyright © 2019. All rights reserved.