Java Code Examples for java.security.SecureClassLoader

The following are top voted examples for showing how to use java.security.SecureClassLoader. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: robopong   File: ClassFileManager.java   Source Code and License 6 votes vote down vote up
/**
 * Will be used by us to get the class loader for our
 * compiled class. It creates an anonymous class
 * extending the SecureClassLoader which uses the
 * byte code created by the compiler and stored in
 * the JavaClassObject, and returns the Class for it
 */
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
        @Override
        protected Class<?> findClass(String name) throws ClassNotFoundException {
            byte[] b = jclassObject.getBytes();
            URL url = null;
            try {
                url = new URL("file://" + DynaCompTest.PADDLES_CODESOURCE);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
            return super.defineClass(name, jclassObject.getBytes(), 0, b.length, new CodeSource(url, new Certificate[0]));
        }
    };
}
 
Example 2
Project: ThriftyPaxos   File: SourceCompiler.java   Source Code and License 5 votes vote down vote up
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
        @Override
        protected Class<?> findClass(String name)
                throws ClassNotFoundException {
            byte[] bytes = classObject.getBytes();
            return super.defineClass(name, bytes, 0,
                    bytes.length);
        }
    };
}
 
Example 3
Project: linden   File: ClassFileManager.java   Source Code and License 5 votes vote down vote up
@Override
public ClassLoader getClassLoader(Location location) {
  return new SecureClassLoader() {
    @Override
    protected Class<?> findClass(String name)
        throws ClassNotFoundException {
      byte[] b = jclassObject.getBytes();
      return super.defineClass(name, jclassObject
          .getBytes(), 0, b.length);
    }
  };
}
 
Example 4
Project: JavaJail   File: RAMClassFileManager.java   Source Code and License 5 votes vote down vote up
/**
 * Will be used by us to get the class loader for our
 * compiled class. It creates an anonymous class
 * extending the SecureClassLoader which uses the
 * byte code created by the compiler and stored in
 * the RAMClassFile, and returns the Class for it
 */
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
       @Override
       protected Class<?> findClass(String name)
            throws ClassNotFoundException {
            byte[] b = contents.get(name).getBytes();
            return super.defineClass(name, b, 0, b.length);
       }
        };
}
 
Example 5
Project: builderator   File: TestCompiler.java   Source Code and License 5 votes vote down vote up
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
        @Override
        protected Class<?> findClass(String name) throws ClassNotFoundException {
            byte[] b = objects.get(name).getBytes();
            return super.defineClass(name, objects.get(name).getBytes(), 0, b.length);
        }
    };
}
 
Example 6
Project: agrona   File: ClassFileManager.java   Source Code and License 5 votes vote down vote up
public ClassLoader getClassLoader(final Location location)
{
    return new SecureClassLoader()
    {
        protected Class<?> findClass(final String name)
        {
            final byte[] buffer = classObjectByNameMap.get(name).getBytes();
            return super.defineClass(name, buffer, 0, buffer.length);
        }
    };
}
 
Example 7
Project: jpexs-decompiler   File: ClassFileManager.java   Source Code and License 5 votes vote down vote up
/**
 * Will be used by us to get the class loader for our compiled class. It
 * creates an anonymous class extending the SecureClassLoader which uses the
 * byte code created by the compiler and stored in the JavaClassObject, and
 * returns the Class for it
 *
 * @param location
 * @return
 */
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
        @Override
        protected Class<?> findClass(String name)
                throws ClassNotFoundException {
            byte[] b = jclassObject.getBytes();
            return super.defineClass(name, jclassObject
                    .getBytes(), 0, b.length);
        }
    };
}
 
Example 8
Project: nocket   File: ClassFileManager.java   Source Code and License 5 votes vote down vote up
/**
 * Will be used by us to get the class loader for our compiled class. It
 * creates an anonymous class extending the SecureClassLoader which uses the
 * byte code created by the compiler and stored in the JavaClassObject, and
 * returns the Class for it
 *
 * @param location the location
 * @return the class loader
 */
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
        @Override
        protected Class<?> findClass(String name)
                throws ClassNotFoundException {
            byte[] b = jclassObject.getBytes();
            return super.defineClass(name, jclassObject.getBytes(), 0,
                    b.length);
        }
    };
}
 
Example 9
Project: mechaverse   File: JavaCompilerUtil.java   Source Code and License 5 votes vote down vote up
@Override
public ClassLoader getClassLoader(Location location) {
  return new SecureClassLoader() {
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
      byte[] b = jclassObject.getBytes();
      return super.defineClass(name, jclassObject.getBytes(), 0, b.length);
    }
  };
}
 
Example 10
Project: logging   File: AbstractFoundationLoggingMarker.java   Source Code and License 5 votes vote down vote up
/**
 * Will be used by us to get the class loader for our compiled class. It
 * creates an anonymous class extending the SecureClassLoader which uses
 * the byte code created by the compiler and stored in the
 * JavaClassObject, and returns the Class for it
 */
@Override
public ClassLoader getClassLoader(Location location) {
	return new SecureClassLoader() {
		@Override
		protected Class<?> findClass(String name) throws ClassNotFoundException {
			byte[] b = jclassObject.getBytes();
			return super.defineClass(name, jclassObject.getBytes(), 0, b.length);
		}
	};
}
 
Example 11
Project: java_jail   File: RAMClassFileManager.java   Source Code and License 5 votes vote down vote up
/**
 * Will be used by us to get the class loader for our
 * compiled class. It creates an anonymous class
 * extending the SecureClassLoader which uses the
 * byte code created by the compiler and stored in
 * the RAMClassFile, and returns the Class for it
 */
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
       @Override
       protected Class<?> findClass(String name)
            throws ClassNotFoundException {
            byte[] b = contents.get(name).getBytes();
            return super.defineClass(name, b, 0, b.length);
       }
        };
}
 
Example 12
Project: syntax-parser   File: ClassFileManager.java   Source Code and License 5 votes vote down vote up
/**
 * Will be used by us to get the class loader for our
 * compiled class. It creates an anonymous class
 * extending the SecureClassLoader which uses the
 * byte code created by the compiler and stored in
 * the JavaClassObject, and returns the Class for it
 */
@Override
public ClassLoader getClassLoader(Location location) {
    return new SecureClassLoader() {
        
        @Override
        protected Class<?> findClass(String name) throws ClassNotFoundException {
            byte[] b = jclassObject.getBytes();
            return super.defineClass(name, jclassObject.getBytes(), 0, b.length);
        }
    };
}
 
Example 13
Project: elasticsearch-lang-java   File: MemoryJavaFileManager.java   Source Code and License 5 votes vote down vote up
@Override
public ClassLoader getClassLoader(Location location) {
	return new SecureClassLoader() {
		@Override
		protected Class<?> findClass(String name) throws ClassNotFoundException {
			byte[] b = javaFileObject.getBytes();
			if (b != null && b.length > 0) {
				return super.defineClass(name, javaFileObject.getBytes(), 0, b.length);
			} else {
				return super.findClass(name);
			}
		}
	};
}
 
Example 14
Project: OpenJSharp   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 15
Project: openjdk-jdk10   File: CanAccessTest.java   Source Code and License 4 votes vote down vote up
protected TestLoader() throws Exception {
    Constructor<?> ctor = SecureClassLoader.class.getDeclaredConstructor();
    assertFalse(ctor.canAccess(null));
    assertFalse(ctor.trySetAccessible());
}
 
Example 16
Project: openjdk-jdk10   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.publicLookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 17
Project: openjdk9   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.publicLookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 18
Project: kaziranga   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 19
Project: lookaside_java-1.8.0-openjdk   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 20
Project: jdk8u_nashorn   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 21
Project: infobip-open-jdk-8   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(final String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(final ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
 
Example 22
Project: OLD-OpenJDK8   File: JavaAdapterServices.java   Source Code and License 4 votes vote down vote up
private static MethodHandle createNoPermissionsInvoker() {
    final String className = "NoPermissionsInvoker";

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
    final Type objectType = Type.getType(Object.class);
    final Type methodHandleType = Type.getType(MethodHandle.class);
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
            Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
            Type.VOID_TYPE, objectType), false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();

    final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new SecureClassLoader(null) {
                @Override
                protected Class<?> findClass(String name) throws ClassNotFoundException {
                    if(name.equals(className)) {
                        return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
                                new CodeSource(null, (CodeSigner[])null), new Permissions()));
                    }
                    throw new ClassNotFoundException(name);
                }
            };
        }
    });

    try {
        return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
                MethodType.methodType(void.class, MethodHandle.class, Object.class));
    } catch(ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}