Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNDERTOW-1773 to avoid potential leak, make sure the iteration continue in case of exception. #949

Merged
merged 1 commit into from
Sep 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -212,7 +212,12 @@ public void servletContextAttributeAdded(final String name, final Object value)
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeAdded(sre);
ManagedListener listener = servletContextAttributeListeners[i];
try {
this.<ServletContextAttributeListener> get(listener).attributeAdded(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeAdded", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -222,7 +227,12 @@ public void servletContextAttributeRemoved(final String name, final Object value
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeRemoved(sre);
ManagedListener listener = servletContextAttributeListeners[i];
try {
this.<ServletContextAttributeListener> get(listener).attributeRemoved(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeRemoved", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -232,7 +242,12 @@ public void servletContextAttributeReplaced(final String name, final Object valu
}
final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value);
for (int i = 0; i < servletContextAttributeListeners.length; ++i) {
this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeReplaced(sre);
ManagedListener listener = servletContextAttributeListeners[i];
try {
this.<ServletContextAttributeListener> get(listener).attributeReplaced(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeReplaced", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -250,10 +265,11 @@ public void requestInitialized(final ServletRequest request) {
} catch (RuntimeException e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("requestInitialized", servletRequestListeners[i].getListenerInfo().getListenerClass(), e);
for (; i >= 0; i--) {
ManagedListener listener = servletRequestListeners[i];
try {
this.<ServletRequestListener>get(servletRequestListeners[i]).requestDestroyed(sre);
this.<ServletRequestListener> get(listener).requestDestroyed(sre);
} catch (Throwable t) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("requestDestroyed", servletRequestListeners[i].getListenerInfo().getListenerClass(), e);
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("requestDestroyed", listener.getListenerInfo().getListenerClass(), e);
}
}
throw e;
Expand Down Expand Up @@ -284,7 +300,13 @@ public void servletRequestAttributeAdded(final HttpServletRequest request, final
}
final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value);
for (int i = 0; i < servletRequestAttributeListeners.length; ++i) {
this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeAdded(sre);
ManagedListener listener = servletRequestAttributeListeners[i];
try {
this.<ServletRequestAttributeListener> get(listener).attributeAdded(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeAdded", listener.getListenerInfo().getListenerClass(), e);
}

}
}

Expand All @@ -294,7 +316,12 @@ public void servletRequestAttributeRemoved(final HttpServletRequest request, fin
}
final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value);
for (int i = 0; i < servletRequestAttributeListeners.length; ++i) {
this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeRemoved(sre);
ManagedListener listener = servletRequestAttributeListeners[i];
try {
this.<ServletRequestAttributeListener> get(listener).attributeRemoved(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeRemoved", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -304,7 +331,12 @@ public void servletRequestAttributeReplaced(final HttpServletRequest request, fi
}
final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value);
for (int i = 0; i < servletRequestAttributeListeners.length; ++i) {
this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeReplaced(sre);
ManagedListener listener = servletRequestAttributeListeners[i];
try {
this.<ServletRequestAttributeListener> get(listener).attributeReplaced(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeReplaced", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -314,7 +346,12 @@ public void sessionCreated(final HttpSession session) {
}
final HttpSessionEvent sre = new HttpSessionEvent(session);
for (int i = 0; i < httpSessionListeners.length; ++i) {
this.<HttpSessionListener>get(httpSessionListeners[i]).sessionCreated(sre);
ManagedListener listener = httpSessionListeners[i];
try {
this.<HttpSessionListener> get(listener).sessionCreated(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("sessionCreated", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -325,7 +362,11 @@ public void sessionDestroyed(final HttpSession session) {
final HttpSessionEvent sre = new HttpSessionEvent(session);
for (int i = httpSessionListeners.length - 1; i >= 0; --i) {
ManagedListener listener = httpSessionListeners[i];
this.<HttpSessionListener>get(listener).sessionDestroyed(sre);
try {
this.<HttpSessionListener> get(listener).sessionDestroyed(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("sessionDestroyed", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -335,7 +376,12 @@ public void httpSessionAttributeAdded(final HttpSession session, final String na
}
final HttpSessionBindingEvent sre = new HttpSessionBindingEvent(session, name, value);
for (int i = 0; i < httpSessionAttributeListeners.length; ++i) {
this.<HttpSessionAttributeListener>get(httpSessionAttributeListeners[i]).attributeAdded(sre);
ManagedListener listener = httpSessionAttributeListeners[i];
try {
this.<HttpSessionAttributeListener> get(listener).attributeAdded(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeAdded", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -345,7 +391,12 @@ public void httpSessionAttributeRemoved(final HttpSession session, final String
}
final HttpSessionBindingEvent sre = new HttpSessionBindingEvent(session, name, value);
for (int i = 0; i < httpSessionAttributeListeners.length; ++i) {
this.<HttpSessionAttributeListener>get(httpSessionAttributeListeners[i]).attributeRemoved(sre);
ManagedListener listener = httpSessionAttributeListeners[i];
try {
this.<HttpSessionAttributeListener> get(httpSessionAttributeListeners[i]).attributeRemoved(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeRemoved", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -355,7 +406,12 @@ public void httpSessionAttributeReplaced(final HttpSession session, final String
}
final HttpSessionBindingEvent sre = new HttpSessionBindingEvent(session, name, value);
for (int i = 0; i < httpSessionAttributeListeners.length; ++i) {
this.<HttpSessionAttributeListener>get(httpSessionAttributeListeners[i]).attributeReplaced(sre);
ManagedListener listener = httpSessionAttributeListeners[i];
try {
this.<HttpSessionAttributeListener> get(listener).attributeReplaced(sre);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("attributeReplaced", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand All @@ -365,7 +421,12 @@ public void httpSessionIdChanged(final HttpSession session, final String oldSess
}
final HttpSessionEvent sre = new HttpSessionEvent(session);
for (int i = 0; i < httpSessionIdListeners.length; ++i) {
this.<HttpSessionIdListener>get(httpSessionIdListeners[i]).sessionIdChanged(sre, oldSessionId);
ManagedListener listener = httpSessionIdListeners[i];
try {
this.<HttpSessionIdListener> get(listener).sessionIdChanged(sre, oldSessionId);
} catch (Exception e) {
UndertowServletLogger.REQUEST_LOGGER.errorInvokingListener("sessionIdChanged", listener.getListenerInfo().getListenerClass(), e);
}
}
}

Expand Down