Search in sources :

Example 1 with ClassLoaderRepository

use of javax.management.loading.ClassLoaderRepository in project jdk8u_jdk by JetBrains.

the class JmxMBeanServer method deserialize.

/**
     * De-serializes a byte array in the context of a given MBean class loader.
     * The class loader is the one that loaded the class with name "className".
     *
     * @param className The name of the class whose class loader should be
     *      used for the de-serialization.
     * @param data The byte array to be de-sererialized.
     *
     * @return  The de-serialized object stream.
     *
     * @exception OperationsException Any of the usual Input/Output
     *      related exceptions.
     * @exception ReflectionException The specified class could not be
     *      loaded by the default loader repository
     *
     */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException, ReflectionException {
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null className passed in parameter");
    }
    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();
    Class<?> theClass;
    try {
        if (clr == null)
            throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e, "The given class could not be " + "loaded by the default loader " + "repository");
    }
    return instantiator.deserialize(theClass.getClassLoader(), data);
}
Also used : ClassLoaderRepository(javax.management.loading.ClassLoaderRepository) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with ClassLoaderRepository

use of javax.management.loading.ClassLoaderRepository in project jdk8u_jdk by JetBrains.

the class RequiredModelMBean method loadClass.

private Class<?> loadClass(final String className) throws ClassNotFoundException {
    AccessControlContext stack = AccessController.getContext();
    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];
    Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {

        @Override
        public Class<?> run() {
            try {
                ReflectUtil.checkPackageAccess(className);
                return Class.forName(className);
            } catch (ClassNotFoundException e) {
                final ClassLoaderRepository clr = getClassLoaderRepository();
                try {
                    if (clr == null)
                        throw new ClassNotFoundException(className);
                    return clr.loadClass(className);
                } catch (ClassNotFoundException ex) {
                    caughtException[0] = ex;
                }
            }
            return null;
        }
    }, stack, acc);
    if (caughtException[0] != null) {
        throw caughtException[0];
    }
    return c;
}
Also used : ClassLoaderRepository(javax.management.loading.ClassLoaderRepository) AccessControlContext(java.security.AccessControlContext)

Aggregations

ClassLoaderRepository (javax.management.loading.ClassLoaderRepository)2 AccessControlContext (java.security.AccessControlContext)1 ReflectionException (javax.management.ReflectionException)1 RuntimeOperationsException (javax.management.RuntimeOperationsException)1