Reputation: 1670
I have this Java code working in Jetty version:
implementation 'org.eclipse.jetty:jetty-util:11.0.20'
Code:
import org.eclipse.jetty.util.MultiException;
RuntimeException rethrownException = originalException;
MultiException multiException = new MultiException();
multiException.add(exeption);
multiException.add(e);
rethrownException = new Exception(multiException);
But when I update the Jetty version to 12.x.x Java class org.eclipse.jetty.util.MultiException
is missing.
Do you know what is the proper way to migrate the code for Jetty 12?
Upvotes: 0
Views: 109
Reputation: 49515
Now that we are using a more modern version of Java, use suppressed exception.
RuntimeException runtimeEx = new RuntimeException(originalException);
runtimeEx.addSuppressed(exception);
runtimeEx.addSuppressed(e);
throw runtimeEx;
But this can lead to circular references, which some libraries (like logging libraries) really do not like.
So there's a org.eclipse.jetty.util.ExceptionUtil.addSuppressedIfNotAssociated(Throwable, Throwable)
to help with that.
The above changes to ...
import org.eclipse.jetty.util.ExceptionUtil;
RuntimeException runtimeEx = new RuntimeException(originalException);
ExceptionUtil.addSuppressedIfNotAssociated(runtimeEx, exception);
ExceptionUtil.addSuppressedIfNotAssociated(runtimeEx, e);
throw runtimeEx;
The ExceptionUtil.addSuppressedIfNotAssociated
will not add the suppressed if it would cause a circular reference. (no point anyway, as the information is already present in the stacktrace)
Upvotes: 1