/** * Transforms the given throwable to the {@link RemoteException}. * * @param throwable * {@link Throwable} to transform. * @param visitedException * List of already processed exceptions. * @return {@link RemoteException} * @throws IllegalAccessException * If set can not be executed on the * {@link ExceptionInterceptor#throwableCauseField}. */ private static RemoteException transformException(Throwable throwable, List<Throwable> visitedException) throws IllegalAccessException { if ((throwable == null) || !visitedException.add(throwable) || (throwable instanceof RemoteException)) { return null; } RemoteException transformedException = new RemoteException(throwable); throwableCauseField.set(transformedException, transformException(throwable.getCause(), visitedException)); return transformedException; } }
/** * Tests serialization of remote exception. */ @Test public void remoteException() throws SerializationException { Exception exception = new Exception("Cause message"); RemoteException remoteException = new RemoteException(exception); Exception deserialized = serializeBackAndForth(remoteException); assertThat(deserialized, is(instanceOf(RemoteException.class))); assertThat(deserialized.getMessage(), is(equalTo(exception.getMessage()))); assertThat(deserialized.getStackTrace(), is(equalTo(exception.getStackTrace()))); }