Fixes #2663 - Guard Throwable.addSuppressed() calls. (#2665)

* Fixes #2663 - Guard Throwable.addSuppressed() calls.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-06-14 15:21:44 +02:00 committed by GitHub
parent f9b5949541
commit 253c637742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 38 deletions

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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);
}
}
};
}

View File

@ -534,7 +534,7 @@ public class WebAppClassLoader extends URLClassLoader
{
if (ex==null)
ex = e;
else
else if (e != ex)
ex.addSuppressed(e);
}