-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Version
4.5.11
Context
We have a subclass of ServiceException that uses initCause to set the cause of the ServiceException and have a customized codec to encode/decode the cause.
However, after recent change in ReplyException (which the ServiceException extends) in vertx 4.5.11: eclipse-vertx/vert.x#5335 , we can no longer use initCause for it because the constructor public ReplyException(ReplyFailure failureType, int failureCode, String message) which the ServiceException calls now init the cause with null.
The ServiceException may need to also provide a protected method with cause that allows sub-class to set the cause on it, to match ReplyException.
Do you have a reproducer?
A small unit test that illustrates the problem:
public static class TestServiceException extends ServiceException {
public TestServiceException(int failureCode, String message, Throwable cause) {
super(failureCode, message);
initCause(cause);
}
}
@Test
public void testServiceExceptionWithCause() {
Throwable cause = new NullPointerException("test cause");
ServiceException serviceException = new TestServiceException(123, "abc", cause);
assertSame(serviceException.getCause(), cause);
}This test case passed on vertx 4.5.10 but failed on vertx 4.5.11:
java.lang.IllegalStateException: Can't overwrite cause with java.lang.NullPointerException: test cause
at java.base/java.lang.Throwable.initCause(Throwable.java:462)
...
Caused by: (RECIPIENT_FAILURE,123) abc