Class<?> defineClass(String name, byte[] bcode, int off, int len, Class<?> neighbor, ClassLoader loader, ProtectionDomain protectionDomain) throws ClassFormatError, CannotCompileException { if (neighbor != null) return toClass(neighbor, bcode); else { // Lookup#defineClass() is not available. So fallback to invoking defineClass on // ClassLoader, which causes a warning message. return super.defineClass(name, bcode, off, len, neighbor, loader, protectionDomain); } } }
/** * Loads a class file by a given class loader. * * @param neighbor a class belonging to the same package that * the loaded class belongs to. * It can be null. * @param loader The class loader. It can be null if {@code neighbor} * is not null. * @param domain if it is null, a default domain is used. * @since 3.3 */ public static Class<?> toClass(ClassFile cf, Class<?> neighbor, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException { try { byte[] b = toBytecode(cf); if (ProxyFactory.onlyPublicMethods) return DefineClassHelper.toPublicClass(cf.getName(), b); else return DefineClassHelper.toClass(cf.getName(), neighbor, loader, domain, b); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Loads a class file by a given lookup. * * @param lookup used to define the class. * @since 3.24 */ public static Class<?> toClass(ClassFile cf, java.lang.invoke.MethodHandles.Lookup lookup) throws CannotCompileException { try { byte[] b = toBytecode(cf); return DefineClassHelper.toClass(lookup, b); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Converts the class to a <code>java.lang.Class</code> object. * Once this method is called, further modifications are not allowed * any more. * * <p>This method is available in Java 9 or later. * It loads the class * by using the given {@code java.lang.invoke.MethodHandles.Lookup}. * </p> * * @param ct the class converted into {@code java.lang.Class}. * @since 3.24 */ public Class<?> toClass(CtClass ct, java.lang.invoke.MethodHandles.Lookup lookup) throws CannotCompileException { try { return javassist.util.proxy.DefineClassHelper.toClass(lookup, ct.toBytecode()); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Converts the class to a <code>java.lang.Class</code> object. * Once this method is called, further modifications are not allowed * any more. * * <p>This method is available in Java 9 or later. * It loads the class * by using {@code java.lang.invoke.MethodHandles} with {@code neighbor}. * </p> * * @param ct the class converted into {@code java.lang.Class}. * @param neighbor a class belonging to the same package that * the converted class belongs to. * @since 3.24 */ public Class<?> toClass(CtClass ct, Class<?> neighbor) throws CannotCompileException { try { return javassist.util.proxy.DefineClassHelper.toClass(neighbor, ct.toBytecode()); } catch (IOException e) { throw new CannotCompileException(e); } }
return javassist.util.proxy.DefineClassHelper.toClass(ct.getName(), neighbor, loader, domain, ct.toBytecode());