code: public static String getFirstStacktrace(Throwable t) {
          if (t == null) {
              return null;
          }
  
          Throwable cause = t;
          while (cause.getCause() != null) {
              cause = cause.getCause();
          }
  
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          try {
              cause.printStackTrace(pw);
          } finally {
              pw.close();
          }
  
          return sw.toString();
      }
docs: Returns the first cause stacktrace for a {@link Throwable throwable}.
  
  @param t the {@link Throwable throwable}
  @return {@link Throwable} the first cause stacktrace for the throwable,
  the original throwable stacktrace if this is the first cause, or
  <tt>null</tt> if the <tt>t</tt> was null