@Test public void causes_are_also_copied_recursively() { Throwable original = new Throwable("original message", new Exception("the cause")); StackTrace copy = StackTrace.from(original); assertThat(copy.getCause(), is(instanceOf(StackTrace.class))); assertThat(copy.getCause().getMessage(), is("the cause")); }
public static StackTrace from(Throwable original) { if (original == null) { return null; } if (original instanceof StackTrace) { return (StackTrace) original; } return new Builder() .setExceptionClass(original.getClass().getName()) .setToString(original.toString()) .setMessage(original.getMessage()) .setStackTrace(original.getStackTrace()) .setCause(original.getCause()) .setSuppressed(original.getSuppressed()) .build(); }
StackTrace extends Throwable { public static StackTrace from(Throwable original) { if (original == null) { return null; } if (original instanceof StackTrace) { return (StackTrace) original; } return new Builder() .setExceptionClass(original.getClass().getName()) .setToString(original.toString()) .setMessage(original.getMessage()) .setStackTrace(original.getStackTrace()) .setCause(original.getCause()) .setSuppressed(original.getSuppressed()) .build(); } }
StackTrace extends Throwable { public static StackTrace from(Throwable original) { if (original == null) { return null; } if (original instanceof StackTrace) { return (StackTrace) original; } return new Builder() .setExceptionClass(original.getClass().getName()) .setToString(original.toString()) .setMessage(original.getMessage()) .setStackTrace(original.getStackTrace()) .setCause(original.getCause()) .setSuppressed(original.getSuppressed()) .build(); } private  StackTrace(String exceptionClass, String toString, String message, StackTrace cause); }
StackTrace extends Throwable { public static StackTrace from(Throwable original) { if (original == null) { return null; } if (original instanceof StackTrace) { return (StackTrace) original; } return new Builder() .setExceptionClass(original.getClass().getName()) .setToString(original.toString()) .setMessage(original.getMessage()) .setStackTrace(original.getStackTrace()) .setCause(original.getCause()) .setSuppressed(original.getSuppressed()) .build(); } private  StackTrace(String exceptionClass, String toString, String message, StackTrace cause); static StackTrace from(Throwable original); @Override synchronized Throwable fillInStackTrace(); String getExceptionClass(); @Override String toString(); }
StackTrace extends Throwable { public static StackTrace from(Throwable original) { if (original == null) { return null; } if (original instanceof StackTrace) { return (StackTrace) original; } return new Builder() .setExceptionClass(original.getClass().getName()) .setToString(original.toString()) .setMessage(original.getMessage()) .setStackTrace(original.getStackTrace()) .setCause(original.getCause()) .setSuppressed(original.getSuppressed()) .build(); } private  StackTrace(String exceptionClass, String toString, String message, StackTrace cause); static StackTrace from(Throwable original); @Override synchronized Throwable fillInStackTrace(); String getExceptionClass(); @Override String toString();  }