1389
1389
* @exception ClassNotFoundException if the class was not found
1391
public Class loadClass(String name, boolean resolve)
1391
public synchronized Class loadClass(String name, boolean resolve)
1392
1392
throws ClassNotFoundException {
1394
synchronized (name.intern()) {
1395
if (log.isDebugEnabled())
1396
log.debug("loadClass(" + name + ", " + resolve + ")");
1399
// Log access to stopped classloader
1402
throw new IllegalStateException();
1403
} catch (IllegalStateException e) {
1404
log.info(sm.getString("webappClassLoader.stopped", name), e);
1408
// (0) Check our previously loaded local class cache
1409
clazz = findLoadedClass0(name);
1410
if (clazz != null) {
1411
if (log.isDebugEnabled())
1412
log.debug(" Returning class from cache");
1414
resolveClass(clazz);
1418
// (0.1) Check our previously loaded class cache
1419
clazz = findLoadedClass(name);
1420
if (clazz != null) {
1421
if (log.isDebugEnabled())
1422
log.debug(" Returning class from cache");
1424
resolveClass(clazz);
1428
// (0.2) Try loading the class with the system class loader, to prevent
1429
// the webapp from overriding J2SE classes
1431
clazz = system.loadClass(name);
1432
if (clazz != null) {
1434
resolveClass(clazz);
1437
} catch (ClassNotFoundException e) {
1441
// (0.5) Permission to access this class when using a SecurityManager
1442
if (securityManager != null) {
1443
int i = name.lastIndexOf('.');
1446
securityManager.checkPackageAccess(name.substring(0,i));
1447
} catch (SecurityException se) {
1448
String error = "Security Violation, attempt to use " +
1449
"Restricted Class: " + name;
1450
log.info(error, se);
1451
throw new ClassNotFoundException(error, se);
1456
boolean delegateLoad = delegate || filter(name);
1458
// (1) Delegate to our parent if requested
1460
if (log.isDebugEnabled())
1461
log.debug(" Delegating to parent classloader1 " + parent);
1462
ClassLoader loader = parent;
1466
clazz = loader.loadClass(name);
1467
if (clazz != null) {
1468
if (log.isDebugEnabled())
1469
log.debug(" Loading class from parent");
1471
resolveClass(clazz);
1474
} catch (ClassNotFoundException e) {
1479
// (2) Search local repositories
1480
if (log.isDebugEnabled())
1481
log.debug(" Searching local repositories");
1483
clazz = findClass(name);
1484
if (clazz != null) {
1485
if (log.isDebugEnabled())
1486
log.debug(" Loading class from local repository");
1488
resolveClass(clazz);
1491
} catch (ClassNotFoundException e) {
1495
// (3) Delegate to parent unconditionally
1496
if (!delegateLoad) {
1497
if (log.isDebugEnabled())
1498
log.debug(" Delegating to parent classloader at end: " + parent);
1499
ClassLoader loader = parent;
1503
clazz = loader.loadClass(name);
1504
if (clazz != null) {
1505
if (log.isDebugEnabled())
1506
log.debug(" Loading class from parent");
1508
resolveClass(clazz);
1511
} catch (ClassNotFoundException e) {
1516
throw new ClassNotFoundException(name);
1394
if (log.isDebugEnabled())
1395
log.debug("loadClass(" + name + ", " + resolve + ")");
1398
// Log access to stopped classloader
1401
throw new IllegalStateException();
1402
} catch (IllegalStateException e) {
1403
log.info(sm.getString("webappClassLoader.stopped", name), e);
1407
// (0) Check our previously loaded local class cache
1408
clazz = findLoadedClass0(name);
1409
if (clazz != null) {
1410
if (log.isDebugEnabled())
1411
log.debug(" Returning class from cache");
1413
resolveClass(clazz);
1417
// (0.1) Check our previously loaded class cache
1418
clazz = findLoadedClass(name);
1419
if (clazz != null) {
1420
if (log.isDebugEnabled())
1421
log.debug(" Returning class from cache");
1423
resolveClass(clazz);
1427
// (0.2) Try loading the class with the system class loader, to prevent
1428
// the webapp from overriding J2SE classes
1430
clazz = system.loadClass(name);
1431
if (clazz != null) {
1433
resolveClass(clazz);
1436
} catch (ClassNotFoundException e) {
1440
// (0.5) Permission to access this class when using a SecurityManager
1441
if (securityManager != null) {
1442
int i = name.lastIndexOf('.');
1445
securityManager.checkPackageAccess(name.substring(0,i));
1446
} catch (SecurityException se) {
1447
String error = "Security Violation, attempt to use " +
1448
"Restricted Class: " + name;
1449
log.info(error, se);
1450
throw new ClassNotFoundException(error, se);
1455
boolean delegateLoad = delegate || filter(name);
1457
// (1) Delegate to our parent if requested
1459
if (log.isDebugEnabled())
1460
log.debug(" Delegating to parent classloader1 " + parent);
1461
ClassLoader loader = parent;
1465
clazz = loader.loadClass(name);
1466
if (clazz != null) {
1467
if (log.isDebugEnabled())
1468
log.debug(" Loading class from parent");
1470
resolveClass(clazz);
1473
} catch (ClassNotFoundException e) {
1478
// (2) Search local repositories
1479
if (log.isDebugEnabled())
1480
log.debug(" Searching local repositories");
1482
clazz = findClass(name);
1483
if (clazz != null) {
1484
if (log.isDebugEnabled())
1485
log.debug(" Loading class from local repository");
1487
resolveClass(clazz);
1490
} catch (ClassNotFoundException e) {
1494
// (3) Delegate to parent unconditionally
1495
if (!delegateLoad) {
1496
if (log.isDebugEnabled())
1497
log.debug(" Delegating to parent classloader at end: " + parent);
1498
ClassLoader loader = parent;
1502
clazz = loader.loadClass(name);
1503
if (clazz != null) {
1504
if (log.isDebugEnabled())
1505
log.debug(" Loading class from parent");
1507
resolveClass(clazz);
1510
} catch (ClassNotFoundException e) {
1515
throw new ClassNotFoundException(name);