### Question:
RpcResult extends AbstractResult { @Override public Object recreate() throws Throwable { if (exception != null) { try { Class clazz = exception.getClass(); while (!clazz.getName().equals(Throwable.class.getName())) { clazz = clazz.getSuperclass(); } Field stackTraceField = clazz.getDeclaredField("stackTrace"); stackTraceField.setAccessible(true); Object stackTrace = stackTraceField.get(exception); if (stackTrace == null) { exception.setStackTrace(new StackTraceElement[0]); } } catch (Exception e) { } throw exception; } return result; } RpcResult();  RpcResult(Object result);  RpcResult(Throwable exception); @Override Object recreate(); @Override @Deprecated Object getResult(); @Deprecated void setResult(Object result); @Override Object getValue(); void setValue(Object value); @Override Throwable getException(); void setException(Throwable e); @Override boolean hasException(); @Override String toString();  }### Answer:
@Test public void testRecreateWithNormalException() { NullPointerException npe = new NullPointerException(); RpcResult rpcResult = new RpcResult(npe); try { rpcResult.recreate(); fail(); } catch (Throwable throwable) { StackTraceElement[] stackTrace = throwable.getStackTrace(); Assertions.assertNotNull(stackTrace); Assertions.assertTrue(stackTrace.length > 1); } }
@Test public void testRecreateWithEmptyStackTraceException() { Throwable throwable = null; Long begin = System.currentTimeMillis(); while (System.currentTimeMillis() - begin < 60000) { try { ((Object) null).getClass(); } catch (Exception e) { if (e.getStackTrace().length == 0) { throwable = e; break; } } } if (throwable == null) { System.out.println("###testRecreateWithEmptyStackTraceException fail to construct NPE"); return; } RpcResult rpcResult = new RpcResult(throwable); try { rpcResult.recreate(); fail(); } catch (Throwable t) { StackTraceElement[] stackTrace = t.getStackTrace(); Assertions.assertNotNull(stackTrace); Assertions.assertTrue(stackTrace.length == 0); } }