From 253c637742e6f0d10147ef1d85238fc5e465a975 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 14 Jun 2018 15:21:44 +0200 Subject: [PATCH] Fixes #2663 - Guard Throwable.addSuppressed() calls. (#2665) * Fixes #2663 - Guard Throwable.addSuppressed() calls. Signed-off-by: Simone Bordet --- .../server/ALPNServerConnectionFactory.java | 6 ++++-- .../org/eclipse/jetty/http2/HTTP2Session.java | 3 ++- .../org/eclipse/jetty/io/WriteFlusher.java | 7 +++++-- .../jetty/server/AsyncContextEvent.java | 2 +- .../org/eclipse/jetty/server/HttpChannel.java | 8 +++++--- .../jetty/server/HttpChannelState.java | 7 ++++--- .../eclipse/jetty/util/MultiException.java | 14 ++++++++------ .../util/component/AbstractLifeCycle.java | 19 ------------------- .../jetty/webapp/WebAppClassLoader.java | 2 +- 9 files changed, 30 insertions(+), 38 deletions(-) diff --git a/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java index 8197f78a794..8c95d5db0cc 100644 --- a/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java +++ b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java @@ -63,7 +63,8 @@ public class ALPNServerConnectionFactory extends NegotiatingServerConnectionFact { if (LOG.isDebugEnabled()) LOG.debug(x); - failure.addSuppressed(x); + if (x != failure) + failure.addSuppressed(x); continue; } @@ -76,7 +77,8 @@ public class ALPNServerConnectionFactory extends NegotiatingServerConnectionFact { if (LOG.isDebugEnabled()) LOG.debug("Could not initialize " + processor, x); - failure.addSuppressed(x); + if (x != failure) + failure.addSuppressed(x); } } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index 86d4077c3bd..57b3f4e1499 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -1550,7 +1550,8 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio @Override public void failed(Throwable x) { - failure.addSuppressed(x); + if (x != failure) + failure.addSuppressed(x); complete(); } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java index 1c08201f6d7..a2d9c8fa008 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java @@ -310,8 +310,11 @@ abstract public class WriteFlusher FailedState failed = (FailedState)_state.get(); Throwable cause = failed.getCause(); - for(Throwable t : suppressed) - cause.addSuppressed(t); + for (Throwable t : suppressed) + { + if (t != cause) + cause.addSuppressed(t); + } callback.failed(cause); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContextEvent.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContextEvent.java index 9d99e8a990a..8c76994250b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContextEvent.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContextEvent.java @@ -168,7 +168,7 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable { if (_throwable==null) _throwable=e; - else if (_throwable != e) + else if (e != _throwable) _throwable.addSuppressed(e); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 5a22723d549..a73c3fd3849 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -428,7 +428,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor } else { - if (failure != x) + if (x != failure) failure.addSuppressed(x); minimalErrorResponse(failure); } @@ -579,7 +579,8 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor } catch (Throwable e) { - failure.addSuppressed(e); + if (e != failure) + failure.addSuppressed(e); LOG.warn("ERROR dispatch failed", failure); // Try to send a minimal response. minimalErrorResponse(failure); @@ -597,7 +598,8 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor } catch (Throwable x) { - failure.addSuppressed(x); + if (x != failure) + failure.addSuppressed(x); abort(failure); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java index 3dfa7ed0313..699f0a4897f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java @@ -593,10 +593,11 @@ public class HttpChannelState { LOG.warn(x+" while invoking onTimeout listener " + listener); LOG.debug(x); - if (error.get()==null) + Throwable failure = error.get(); + if (failure == null) error.set(x); - else - error.get().addSuppressed(x); + else if (x != failure) + failure.addSuppressed(x); } } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java index fb5a0b59d29..f7843c11c48 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java @@ -55,15 +55,15 @@ public class MultiException extends Exception super(DEFAULT_MESSAGE); this.nested = new ArrayList<>(nested); - if(nested.size() > 0) { + if (nested.size() > 0) initCause(nested.get(0)); - } - - for(Throwable t : nested) { - this.addSuppressed(t); + + for (Throwable t : nested) + { + if (t != this) + addSuppressed(t); } } - /* ------------------------------------------------------------ */ public void add(Throwable e) @@ -196,8 +196,10 @@ public class MultiException extends Exception th = new MultiException(Collections.emptyList()); for (Throwable s : nested) + { if (s!=th) th.addSuppressed(s); + } if (Error.class.isInstance(th)) throw (Error)th; throw (Exception)th; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java index f2e9d4469d4..ccb9c6b2b4d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java @@ -234,23 +234,4 @@ public abstract class AbstractLifeCycle implements LifeCycle @Override public void lifeCycleStopped(LifeCycle event) {} @Override public void lifeCycleStopping(LifeCycle event) {} } - - /** - * A LifeCycle Listener that will call stop if any failures are notified. - */ - public static final LifeCycle.Listener STOP_ON_FAILURE = new AbstractLifeCycleListener() - { - @Override - public void lifeCycleFailure(LifeCycle lifecycle, Throwable cause) - { - try - { - lifecycle.stop(); - } - catch(Exception e) - { - cause.addSuppressed(e); - } - } - }; } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index 71a56ffefcf..169580ac109 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -534,7 +534,7 @@ public class WebAppClassLoader extends URLClassLoader { if (ex==null) ex = e; - else + else if (e != ex) ex.addSuppressed(e); }