~ubuntu-branches/ubuntu/natty/tomcat6/natty-proposed

« back to all changes in this revision

Viewing changes to java/org/apache/catalina/loader/WebappClassLoader.java

  • Committer: Bazaar Package Importer
  • Author(s): Marcus Better, Marcus Better, Thierry Carrez
  • Date: 2010-05-31 15:50:57 UTC
  • mfrom: (2.2.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100531155057-2q6116ah6vsnnqit
Tags: 6.0.26-3
[ Marcus Better ]
* Apply upstream fix for deadlock in WebappClassLoader. (Closes: #583896)

[ Thierry Carrez ]
* debian/tomcat6.{install,postinst}: Do not store the default root webapp
  in /usr/share/tomcat6/webapps as it increases confusion on what this
  directory contains (and its relation with /var/lib/tomcat6/webapps).
  Store it inside /usr/share/tomcat6-root instead (LP: #575303).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1388
1388
     *
1389
1389
     * @exception ClassNotFoundException if the class was not found
1390
1390
     */
1391
 
    public Class loadClass(String name, boolean resolve)
 
1391
    public synchronized Class loadClass(String name, boolean resolve)
1392
1392
        throws ClassNotFoundException {
1393
1393
 
1394
 
        synchronized (name.intern()) {
1395
 
            if (log.isDebugEnabled())
1396
 
                log.debug("loadClass(" + name + ", " + resolve + ")");
1397
 
            Class clazz = null;
1398
 
    
1399
 
            // Log access to stopped classloader
1400
 
            if (!started) {
1401
 
                try {
1402
 
                    throw new IllegalStateException();
1403
 
                } catch (IllegalStateException e) {
1404
 
                    log.info(sm.getString("webappClassLoader.stopped", name), e);
1405
 
                }
1406
 
            }
1407
 
    
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");
1413
 
                if (resolve)
1414
 
                    resolveClass(clazz);
1415
 
                return (clazz);
1416
 
            }
1417
 
    
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");
1423
 
                if (resolve)
1424
 
                    resolveClass(clazz);
1425
 
                return (clazz);
1426
 
            }
1427
 
    
1428
 
            // (0.2) Try loading the class with the system class loader, to prevent
1429
 
            //       the webapp from overriding J2SE classes
1430
 
            try {
1431
 
                clazz = system.loadClass(name);
1432
 
                if (clazz != null) {
1433
 
                    if (resolve)
1434
 
                        resolveClass(clazz);
1435
 
                    return (clazz);
1436
 
                }
1437
 
            } catch (ClassNotFoundException e) {
1438
 
                // Ignore
1439
 
            }
1440
 
    
1441
 
            // (0.5) Permission to access this class when using a SecurityManager
1442
 
            if (securityManager != null) {
1443
 
                int i = name.lastIndexOf('.');
1444
 
                if (i >= 0) {
1445
 
                    try {
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);
1452
 
                    }
1453
 
                }
1454
 
            }
1455
 
    
1456
 
            boolean delegateLoad = delegate || filter(name);
1457
 
    
1458
 
            // (1) Delegate to our parent if requested
1459
 
            if (delegateLoad) {
1460
 
                if (log.isDebugEnabled())
1461
 
                    log.debug("  Delegating to parent classloader1 " + parent);
1462
 
                ClassLoader loader = parent;
1463
 
                if (loader == null)
1464
 
                    loader = system;
1465
 
                try {
1466
 
                    clazz = loader.loadClass(name);
1467
 
                    if (clazz != null) {
1468
 
                        if (log.isDebugEnabled())
1469
 
                            log.debug("  Loading class from parent");
1470
 
                        if (resolve)
1471
 
                            resolveClass(clazz);
1472
 
                        return (clazz);
1473
 
                    }
1474
 
                } catch (ClassNotFoundException e) {
1475
 
                    ;
1476
 
                }
1477
 
            }
1478
 
    
1479
 
            // (2) Search local repositories
1480
 
            if (log.isDebugEnabled())
1481
 
                log.debug("  Searching local repositories");
1482
 
            try {
1483
 
                clazz = findClass(name);
1484
 
                if (clazz != null) {
1485
 
                    if (log.isDebugEnabled())
1486
 
                        log.debug("  Loading class from local repository");
1487
 
                    if (resolve)
1488
 
                        resolveClass(clazz);
1489
 
                    return (clazz);
1490
 
                }
1491
 
            } catch (ClassNotFoundException e) {
1492
 
                ;
1493
 
            }
1494
 
    
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;
1500
 
                if (loader == null)
1501
 
                    loader = system;
1502
 
                try {
1503
 
                    clazz = loader.loadClass(name);
1504
 
                    if (clazz != null) {
1505
 
                        if (log.isDebugEnabled())
1506
 
                            log.debug("  Loading class from parent");
1507
 
                        if (resolve)
1508
 
                            resolveClass(clazz);
1509
 
                        return (clazz);
1510
 
                    }
1511
 
                } catch (ClassNotFoundException e) {
1512
 
                    ;
1513
 
                }
1514
 
            }
1515
 
    
1516
 
            throw new ClassNotFoundException(name);
1517
 
        }
 
1394
        if (log.isDebugEnabled())
 
1395
            log.debug("loadClass(" + name + ", " + resolve + ")");
 
1396
        Class clazz = null;
 
1397
 
 
1398
        // Log access to stopped classloader
 
1399
        if (!started) {
 
1400
            try {
 
1401
                throw new IllegalStateException();
 
1402
            } catch (IllegalStateException e) {
 
1403
                log.info(sm.getString("webappClassLoader.stopped", name), e);
 
1404
            }
 
1405
        }
 
1406
 
 
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");
 
1412
            if (resolve)
 
1413
                resolveClass(clazz);
 
1414
            return (clazz);
 
1415
        }
 
1416
 
 
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");
 
1422
            if (resolve)
 
1423
                resolveClass(clazz);
 
1424
            return (clazz);
 
1425
        }
 
1426
 
 
1427
        // (0.2) Try loading the class with the system class loader, to prevent
 
1428
        //       the webapp from overriding J2SE classes
 
1429
        try {
 
1430
            clazz = system.loadClass(name);
 
1431
            if (clazz != null) {
 
1432
                if (resolve)
 
1433
                    resolveClass(clazz);
 
1434
                return (clazz);
 
1435
            }
 
1436
        } catch (ClassNotFoundException e) {
 
1437
            // Ignore
 
1438
        }
 
1439
 
 
1440
        // (0.5) Permission to access this class when using a SecurityManager
 
1441
        if (securityManager != null) {
 
1442
            int i = name.lastIndexOf('.');
 
1443
            if (i >= 0) {
 
1444
                try {
 
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);
 
1451
                }
 
1452
            }
 
1453
        }
 
1454
 
 
1455
        boolean delegateLoad = delegate || filter(name);
 
1456
 
 
1457
        // (1) Delegate to our parent if requested
 
1458
        if (delegateLoad) {
 
1459
            if (log.isDebugEnabled())
 
1460
                log.debug("  Delegating to parent classloader1 " + parent);
 
1461
            ClassLoader loader = parent;
 
1462
            if (loader == null)
 
1463
                loader = system;
 
1464
            try {
 
1465
                clazz = loader.loadClass(name);
 
1466
                if (clazz != null) {
 
1467
                    if (log.isDebugEnabled())
 
1468
                        log.debug("  Loading class from parent");
 
1469
                    if (resolve)
 
1470
                        resolveClass(clazz);
 
1471
                    return (clazz);
 
1472
                }
 
1473
            } catch (ClassNotFoundException e) {
 
1474
                ;
 
1475
            }
 
1476
        }
 
1477
 
 
1478
        // (2) Search local repositories
 
1479
        if (log.isDebugEnabled())
 
1480
            log.debug("  Searching local repositories");
 
1481
        try {
 
1482
            clazz = findClass(name);
 
1483
            if (clazz != null) {
 
1484
                if (log.isDebugEnabled())
 
1485
                    log.debug("  Loading class from local repository");
 
1486
                if (resolve)
 
1487
                    resolveClass(clazz);
 
1488
                return (clazz);
 
1489
            }
 
1490
        } catch (ClassNotFoundException e) {
 
1491
            ;
 
1492
        }
 
1493
 
 
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;
 
1499
            if (loader == null)
 
1500
                loader = system;
 
1501
            try {
 
1502
                clazz = loader.loadClass(name);
 
1503
                if (clazz != null) {
 
1504
                    if (log.isDebugEnabled())
 
1505
                        log.debug("  Loading class from parent");
 
1506
                    if (resolve)
 
1507
                        resolveClass(clazz);
 
1508
                    return (clazz);
 
1509
                }
 
1510
            } catch (ClassNotFoundException e) {
 
1511
                ;
 
1512
            }
 
1513
        }
 
1514
 
 
1515
        throw new ClassNotFoundException(name);
 
1516
 
1518
1517
    }
1519
1518
 
1520
1519
 
2469
2468
        if (clazz != null)
2470
2469
            return clazz;
2471
2470
 
2472
 
        synchronized (name.intern()) {
 
2471
        synchronized (this) {
2473
2472
            clazz = entry.loadedClass;
2474
2473
            if (clazz != null)
2475
2474
                return clazz;