Skip to content

Commit

Permalink
Merge pull request #953 from soul2zimate/UNDERTOW-1773-2.1.x
Browse files Browse the repository at this point in the history
UNDERTOW-1773 to avoid leak, make sure the iteration continue in case…
  • Loading branch information
ropalka committed Sep 24, 2020
2 parents a9fc8e8 + 8d04563 commit b704ce0
Showing 1 changed file with 75 additions and 14 deletions.
Original file line number Diff line number Diff line change
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

0 comments on commit b704ce0

Please sign in to comment.