/** * Recreate the invocation result, either returning the result value * in case of a successful invocation of the target method, or * rethrowing the exception thrown by the target method. * @return the result value, if any * @throws Throwable the exception, if any */ @Nullable public Object recreate() throws Throwable { if (this.exception != null) { Throwable exToThrow = this.exception; if (this.exception instanceof InvocationTargetException) { exToThrow = ((InvocationTargetException) this.exception).getTargetException(); } RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow); throw exToThrow; } else { return this.value; } }
/** * Recreate the invocation result, either returning the result value * in case of a successful invocation of the target method, or * rethrowing the exception thrown by the target method. * @return the result value, if any * @throws Throwable the exception, if any */ @Nullable public Object recreate() throws Throwable { if (this.exception != null) { Throwable exToThrow = this.exception; if (this.exception instanceof InvocationTargetException) { exToThrow = ((InvocationTargetException) this.exception).getTargetException(); } RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow); throw exToThrow; } else { return this.value; } }
@Test public void fillInClientStackTraceIfPossibleWithNullThrowable() throws Exception { // just want to ensure that it doesn't bomb RemoteInvocationUtils.fillInClientStackTraceIfPossible(null); }
@Test public void fillInClientStackTraceIfPossibleSunnyDay() throws Exception { try { throw new IllegalStateException("Mmm"); } catch (Exception ex) { int originalStackTraceLngth = ex.getStackTrace().length; RemoteInvocationUtils.fillInClientStackTraceIfPossible(ex); assertTrue("Stack trace not being filled in", ex.getStackTrace().length > originalStackTraceLngth); } }
RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow); throw exToThrow;
RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow); throw exToThrow;
/** * Recreate the invocation result, either returning the result value * in case of a successful invocation of the target method, or * rethrowing the exception thrown by the target method. * @return the result value, if any * @throws Throwable the exception, if any */ @Nullable public Object recreate() throws Throwable { if (this.exception != null) { Throwable exToThrow = this.exception; if (this.exception instanceof InvocationTargetException) { exToThrow = ((InvocationTargetException) this.exception).getTargetException(); } RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow); throw exToThrow; } else { return this.value; } }
@Override protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { Throwable throwable = result.getException(); if (throwable != null) { if (throwable instanceof InvocationTargetException) throwable = ((InvocationTargetException) throwable).getTargetException(); if (throwable instanceof RemoteException) { Exception exception = ((RemoteException) throwable).getFirstCauseException(); // This is a checked exception declared in a service method // or runtime exception supported by client if (exception != null) { RemoteInvocationUtils.fillInClientStackTraceIfPossible(exception); throw exception; } } } return super.recreateRemoteInvocationResult(result); } }
RemoteInvocationUtils.fillInClientStackTraceIfPossible(exToThrow); throw exToThrow;