From: markt Date: Tue, 12 Jan 2010 22:36:15 +0000 (+0000) Subject: Improved fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=47774 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=fca82790db1b70d18ac5f65485897734d188e68e;p=tomcat7.0 Improved fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=47774 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@898555 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/session/StandardSession.java b/java/org/apache/catalina/session/StandardSession.java index e69ce68db..19f061272 100644 --- a/java/org/apache/catalina/session/StandardSession.java +++ b/java/org/apache/catalina/session/StandardSession.java @@ -702,37 +702,55 @@ public class StandardSession // Notify interested application event listeners // FIXME - Assumes we call listeners in reverse order Context context = (Context) manager.getContainer(); - Object listeners[] = context.getApplicationLifecycleListeners(); - if (notify && (listeners != null)) { - HttpSessionEvent event = - new HttpSessionEvent(getSession()); - for (int i = 0; i < listeners.length; i++) { - int j = (listeners.length - 1) - i; - if (!(listeners[j] instanceof HttpSessionListener)) - continue; - HttpSessionListener listener = - (HttpSessionListener) listeners[j]; - try { - fireContainerEvent(context, - "beforeSessionDestroyed", - listener); - listener.sessionDestroyed(event); - fireContainerEvent(context, - "afterSessionDestroyed", - listener); - } catch (Throwable t) { + + // The call to expire() may not have been triggered by the webapp. + // Make sure the webapp's class loader is set when calling the + // listeners + ClassLoader oldTccl = null; + if (context.getLoader() != null && + context.getLoader().getClassLoader() != null) { + oldTccl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader( + context.getLoader().getClassLoader()); + } + try { + Object listeners[] = context.getApplicationLifecycleListeners(); + if (notify && (listeners != null)) { + HttpSessionEvent event = + new HttpSessionEvent(getSession()); + for (int i = 0; i < listeners.length; i++) { + int j = (listeners.length - 1) - i; + if (!(listeners[j] instanceof HttpSessionListener)) + continue; + HttpSessionListener listener = + (HttpSessionListener) listeners[j]; try { fireContainerEvent(context, + "beforeSessionDestroyed", + listener); + listener.sessionDestroyed(event); + fireContainerEvent(context, "afterSessionDestroyed", listener); - } catch (Exception e) { - // Ignore + } catch (Throwable t) { + try { + fireContainerEvent(context, + "afterSessionDestroyed", + listener); + } catch (Exception e) { + // Ignore + } + manager.getContainer().getLogger().error + (sm.getString("standardSession.sessionEvent"), t); } - manager.getContainer().getLogger().error - (sm.getString("standardSession.sessionEvent"), t); } } + } finally { + if (oldTccl != null) { + Thread.currentThread().setContextClassLoader(oldTccl); + } } + if (ACTIVITY_CHECK) { accessCount.set(0); }