code: static Throwable unwrapException(Throwable wrapped, StringBuilder outAction) {
          Throwable unwrapped = wrapped;
  
          while ((unwrapped instanceof ExecutionException) || (unwrapped instanceof CompletionException)
                  || (unwrapped instanceof ExceptionWithAction)) {
              if ((unwrapped instanceof ExceptionWithAction) && (outAction != null)) {
                  // Save the action string from an ExceptionWithAction, if desired.
                  outAction.append(((ExceptionWithAction) unwrapped).getAction());
              }
  
              if ((unwrapped.getCause() != null) && (unwrapped.getCause() instanceof Exception)) {
                  unwrapped = unwrapped.getCause();
              } else {
                  break;
              }
          }
  
          return unwrapped;
      }
docs: outAction can be null if you don't care about any action string