public class DefineClassHelper extends Object
ClassLoader.defineClass(String,byte[],int,int)
.Modifier and Type | Method | Description |
---|---|---|
static Class<?> |
toClass(String className,
ClassLoader loader,
ProtectionDomain domain,
byte[] bcode) |
Loads a class file by a given class loader.
|
public static Class<?> toClass(String className, ClassLoader loader, ProtectionDomain domain, byte[] bcode) throws CannotCompileException
This first tries to use sun.misc.Unsafe
to load a class.
Then it tries to use a protected
method in java.lang.ClassLoader
via PrivilegedAction
. Since the latter approach is not available
any longer by default in Java 9 or later, the JVM argument
--add-opens java.base/java.lang=ALL-UNNAMED
must be given to the JVM.
If this JVM argument cannot be given, toPublicClass(String,byte[])
should be used instead.
domain
- if it is null, a default domain is used.CannotCompileException
Copyright © 2018 Shigeru Chiba, www.javassist.org. All rights reserved.