Package org.jboss.weld.util.bytecode
Class ClassFileUtils
- java.lang.Object
-
- org.jboss.weld.util.bytecode.ClassFileUtils
-
public class ClassFileUtils extends Object
Utility class for loading a ClassFile into a classloader. Allows to use either old approach directly via CL methods, or delegation to integrator throughProxyServices
. Also contains logic needed to crack open CL methods should that approach be used - this is invoked from WeldStartup. As we need to be able to define classes with different ProtectionDomain, we still have to crack open CL methods via setAccessible() which means there will be IllegalAccess warnings. Unsafe is no longer an option on JDK 12+.. This mostly concerns Weld SE, EE integrators should already go through new SPI hence avoiding this problem.- Author:
- Stuart Douglas, Matej Novotny
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
makeClassLoaderMethodsAccessible()
This method cracks openClassLoader#defineClass()
methods by callingsetAccessible()
.static Class<?>
toClass(org.jboss.classfilewriter.ClassFile ct, Class<?> originalClass, org.jboss.weld.serialization.spi.ProxyServices proxyServices, ProtectionDomain domain)
Delegates proxy creation viaProxyServices
to the integrator.static Class<?>
toClass(org.jboss.classfilewriter.ClassFile ct, ClassLoader loader, ProtectionDomain domain)
Converts the class to ajava.lang.Class
object.
-
-
-
Method Detail
-
makeClassLoaderMethodsAccessible
public static void makeClassLoaderMethodsAccessible()
This method cracks openClassLoader#defineClass()
methods by callingsetAccessible()
. It is invoked duringWeldStartup#startContainer()
and only in case the integrator does not fully implementProxyServices
.
-
toClass
public static Class<?> toClass(org.jboss.classfilewriter.ClassFile ct, ClassLoader loader, ProtectionDomain domain)
Converts the class to ajava.lang.Class
object. Once this method is called, further modifications are not allowed any more. The class file represented by the givenCtClass
is loaded by the given class loader to construct ajava.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 obtainProtectionDomain
object is to callgetProtectionDomain()
injava.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.- Parameters:
loader
- the class loader used to load this class. For example, the loader returned bygetClassLoader()
can be used for this parameter.domain
- the protection domain for the class. If it is null, the default domain created byjava.lang.ClassLoader
is
-
toClass
public static Class<?> toClass(org.jboss.classfilewriter.ClassFile ct, Class<?> originalClass, org.jboss.weld.serialization.spi.ProxyServices proxyServices, ProtectionDomain domain)
Delegates proxy creation viaProxyServices
to the integrator.
-
-