Search in sources :

Example 11 with ResourceEntry

use of org.glassfish.api.deployment.ResourceEntry in project Payara by payara.

the class WebappClassLoader method findClass.

// ---------------------------------------------------- ClassLoader Methods
/**
 * Find the specified class in our local repositories, if possible.  If
 * not found, throw <code>ClassNotFoundException</code>.
 *
 * @param name Name of the class to be loaded
 *
 * @exception ClassNotFoundException if the class was not found
 */
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER, "    findClass({0})", name);
    }
    // if (securityManager != null) {
    if (securityManager != null && packageDefinitionEnabled) {
        // END PE 4989455
        int i = name.lastIndexOf('.');
        if (i >= 0) {
            try {
                if (logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER, "      securityManager.checkPackageDefinition");
                }
                securityManager.checkPackageDefinition(name.substring(0, i));
            } catch (Exception se) {
                if (logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER, "      -->Exception-->ClassNotFoundException", se);
                }
                throw new ClassNotFoundException(name, se);
            }
        }
    }
    // Ask our superclass to locate this class, if possible
    // (throws ClassNotFoundException if it is not found)
    Class<?> clazz = null;
    try {
        if (logger.isLoggable(Level.FINER)) {
            logger.log(Level.FINER, "      findClassInternal({0})", name);
        }
        try {
            ResourceEntry entry = findClassInternal(name);
            synchronized (this) {
                if (entry.loadedClass == null) {
                    clazz = defineLoadedClass(name, entry);
                } else {
                    clazz = entry.loadedClass;
                }
            }
        } catch (ClassNotFoundException cnfe) {
            if (!hasExternalRepositories) {
                throw cnfe;
            }
        } catch (UnsupportedClassVersionError ucve) {
            throw new UnsupportedClassVersionError(getString(LogFacade.UNSUPPORTED_VERSION, name, getJavaVersion()));
        } catch (AccessControlException ace) {
            if (logger.isLoggable(Level.WARNING)) {
                logger.log(Level.WARNING, LogFacade.FIND_CLASS_INTERNAL_SECURITY_EXCEPTION, new Object[] { name, ace.getMessage() });
            }
            throw new ClassNotFoundException(name, ace);
        } catch (RuntimeException | Error rex) {
            throw rex;
        } catch (Throwable t) {
            throw new RuntimeException(getString(LogFacade.UNABLE_TO_LOAD_CLASS, name, t.toString()), t);
        }
        if ((clazz == null) && hasExternalRepositories) {
            try {
                clazz = super.findClass(name);
            } catch (AccessControlException ace) {
                if (logger.isLoggable(Level.WARNING)) {
                    String msg = getString(LogFacade.FIND_CLASS_INTERNAL_SECURITY_EXCEPTION, new Object[] { name, ace.getMessage() });
                    logger.log(Level.WARNING, msg, ace);
                }
                throw new ClassNotFoundException(name, ace);
            } catch (RuntimeException e) {
                if (logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER, "      -->RuntimeException Rethrown", e);
                }
                throw e;
            }
        }
        if (clazz == null) {
            if (logger.isLoggable(Level.FINER)) {
                logger.log(Level.FINER, "    --> Returning ClassNotFoundException");
            }
            throw new ClassNotFoundException(name);
        }
    } catch (ClassNotFoundException e) {
        if (logger.isLoggable(Level.FINER)) {
            logger.log(Level.FINER, "    --> Passing on ClassNotFoundException");
        }
        throw e;
    }
    // Return the class we have located
    if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER, "      Returning class {0}", clazz);
    }
    if (logger.isLoggable(Level.FINER)) {
        ClassLoader cl;
        if (securityManager != null) {
            cl = AccessController.doPrivileged(new PrivilegedGetClassLoader(clazz));
        } else {
            cl = clazz.getClassLoader();
        }
        logger.log(Level.FINER, "      Loaded by {0}", cl);
    }
    return clazz;
}
Also used : NamingException(javax.naming.NamingException) IllegalClassFormatException(java.lang.instrument.IllegalClassFormatException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) GeneratedResourceEntry(org.glassfish.api.deployment.GeneratedResourceEntry) ResourceEntry(org.glassfish.api.deployment.ResourceEntry) URLClassLoader(java.net.URLClassLoader) InstrumentableClassLoader(org.glassfish.api.deployment.InstrumentableClassLoader) ResourceClassLoader(org.glassfish.api.deployment.ResourceClassLoader)

Aggregations

ResourceEntry (org.glassfish.api.deployment.ResourceEntry)11 GeneratedResourceEntry (org.glassfish.api.deployment.GeneratedResourceEntry)10 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)3 JarFile (java.util.jar.JarFile)3 ZipFile (java.util.zip.ZipFile)3 NamingException (javax.naming.NamingException)3 ResourceClassLoader (org.glassfish.api.deployment.ResourceClassLoader)3 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URLClassLoader (java.net.URLClassLoader)2 InstrumentableClassLoader (org.glassfish.api.deployment.InstrumentableClassLoader)2 HotSwapHelper (com.sun.enterprise.glassfish.bootstrap.MainHelper.HotSwapHelper)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1