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;
}
Aggregations