private static List<StackTraceElementMessage>
    toStackTraceElementMessages(StackTraceElement[] trace) {
    // if there is no stack trace, ignore it and just return the message
    if (trace == null) return null;
    // build the stack trace for the message
    List<StackTraceElementMessage> pbTrace = new ArrayList<>(trace.length);
    for (StackTraceElement elem : trace) {
      StackTraceElementMessage.Builder stackBuilder = StackTraceElementMessage.newBuilder();
      stackBuilder.setDeclaringClass(elem.getClassName());
      stackBuilder.setFileName(elem.getFileName());
      stackBuilder.setLineNumber(elem.getLineNumber());
      stackBuilder.setMethodName(elem.getMethodName());
      pbTrace.add(stackBuilder.build());
    }
    return pbTrace;
  }
Convert a stack trace to list of {@link StackTraceElement}.
@param trace the stack trace to convert to protobuf message
@return <tt>null</tt> if the passed stack is <tt>null</tt>.
hbase-server/src/main/java/org/apache/hadoop/hbase/errorhandling/ForeignException.java