public static UserCodeException wrap(Throwable t) {
    if (t instanceof UserCodeException) {
      return (UserCodeException) t;
    }

    return new UserCodeException(t);
  }
@Test
  public void robustAgainstEmptyStackTrace() {
    RuntimeException runtimeException = new RuntimeException("empty stack");
    runtimeException.setStackTrace(new StackTraceElement[0]);
    RuntimeException wrapped = UserCodeException.wrap(runtimeException);
    assertEquals(runtimeException, wrapped.getCause());
  }