code: private static Throwable getRootCause(Throwable throwable) {
          List<Throwable> list = new ArrayList<>();
          while (throwable != null && !list.contains(throwable)) {
              list.add(throwable);
              throwable = throwable.getCause();
          }
          return list.get(list.size() - 1);
      }
docs: Get the root cause from a <code>Throwable</code> stack
  
  @param throwable
  @return