Mimics a direct call to {@code getStackTraceDepth()} on the JavaLangAccess interface without
requiring the Java runtime to directly reference the method (which may not exist on some
JVMs).
425707
public int getStackTraceDepth(Throwable throwable) {
    try {
      return (int) (Integer) getDepthMethod.invoke(javaLangAccess, throwable);
    } catch (InvocationTargetException e) {
      // There really should be no chance of runtime errors.
      if (e.getCause() instanceof RuntimeException) {
        throw (RuntimeException) e.getCause();
      } else if (e.getCause() instanceof Error) {
        throw (Error) e.getCause();
      }
      // This should not be possible because the getStackTraceElement() method does not declare
      // any checked exceptions (though APIs may change over time).
      throw new RuntimeException(e.getCause());
    } catch (IllegalAccessException e) {
      // This should never happen because the method has been successfully invoked once already.
      throw new AssertionError(e);
    }
  }
440467
@Benchmark
	@BenchmarkMode(Mode.Throughput)
	public StackFrame stackWalkerWithAnonymousClass() {
		return StackWalker.getInstance().walk(new Function<Stream<StackFrame>, StackFrame>() {
			@Override
			public StackFrame apply(final Stream<StackFrame> stream) {
				return stream.skip(1).findFirst().get();
			}
		});
	}
409408
private String getStackTrace(AbstractRestException data) {
        StringBuilderWriter writer = new StringBuilderWriter();
        try {
            data.printStackTrace(new PrintWriter(writer));
            return writer.getBuilder().toString();
        } finally {
            writer.close();
        }
    }
915415
private String filterStackTrace(String trace) {
    for (StackTraceFilter filter : stackFilters) {
      trace = filter.apply(trace);
    }
    return trace;
  }
591586
public static String filterdStackTrace(String stackTrace) {
    boolean skip = false;
    StringBuilder filteredStackTrace = new StringBuilder();
    // read line by line until the reflective call to the test method is found
    String[] segments = stackTrace.split("\n");
    for (int i = 0; i < segments.length; i++) {
      String segment = segments[i];
      
      if (skip) {
        // check if Cause by appears then stop skip
        if (segment.startsWith("Caused by:")) {
          skip = false;
          filteredStackTrace.append(segment).append("\n");
        }
      }
      else {
        if (segment.startsWith("\tat sun.reflect.NativeMethodAccessorImpl")) {
          // skip all lines until Caused by appears
          skip = true;
        }
        else if (segment.startsWith("\tat org.junit.") || segment.startsWith("\tat junit.framework.")) {
          // skip
        }
        else {
          filteredStackTrace.append(segment).append("\n");
        }
      }
    }
    // remove last newline
    filteredStackTrace.delete(filteredStackTrace.length()-1, filteredStackTrace.length());
    return filteredStackTrace.toString();
  }
754072
private static StackTraceElementsFiller getStackTraceElementsFiller() {
		try {
			Method method = VMStack.class.getDeclaredMethod("fillStackTraceElements", Thread.class, StackTraceElement[].class);
			method.setAccessible(true);
			StackTraceElement[] trace = new StackTraceElement[STACK_TRACE_SIZE];
			method.invoke(null, Thread.currentThread(), trace);
			for (int i = 0; i < STACK_TRACE_SIZE; ++i) {
				StackTraceElement element = trace[i];
				if (element != null && AndroidRuntime.class.getName().equals(element.getClassName())
					&& "getStackTraceElementsFiller".equals(element.getMethodName())) {
					return new StackTraceElementsFiller(method, i);
				}
			}
			return new StackTraceElementsFiller(null, -1);
		} catch (NoClassDefFoundError error) {
			return new StackTraceElementsFiller(null, -1);
		} catch (Exception ex) {
			return new StackTraceElementsFiller(null, -1);
		}
	}
1074031
public String getStack() {
		if (stackTrace == null) {
			if (stack == null) {
				StringWriter sw = new StringWriter(512);
				PrintWriter pw = new PrintWriter(sw, true);
				super.printStackTrace(pw);
				stackTrace = sw.toString().trim();
			} else {
				stackTrace = stack.trim();
			}
		}
		return stackTrace;
	}
697517
public static String getStackTrace( Throwable throwable ) {
        if (throwable == null) return null;
        final ByteArrayOutputStream bas = new ByteArrayOutputStream();
        final PrintWriter pw = new PrintWriter(bas);
        throwable.printStackTrace(pw);
        pw.close();
        return bas.toString();
    }
645900
function getStackTraceArray() {
  var origStackTraceLimit = Error.stackTraceLimit
  var origPrepareStackTrace = Error.prepareStackTrace

  // Collect all stack frames.
  Error.stackTraceLimit = Infinity

  // Get a structured stack trace as an `Array` of `CallSite` objects, each of which represents a stack frame, with frames for native Node functions and this file removed.
  Error.prepareStackTrace = function (error, structuredStackTrace) {
    return structuredStackTrace.filter(function (frame) {
      var filePath = frame.getFileName()

      // Skip frames from within this module (i.e., `dantil`).
      if (filePath === __filename) {
        return false
      }

      // Skip frames for native Node functions (e.g., `require()`).
      if (!/\//.test(filePath)) {
        return false
      }

      return true
    })
  }

  // Collect the stack trace.
  var stack = Error().stack

  // Restore stack trace configuration after collecting stack trace.
  Error.stackTraceLimit = origStackTraceLimit
  Error.prepareStackTrace = origPrepareStackTrace

  return stack
}
486354
@JsonProperty("stack_trace")
	public String getStackTraceString() {
		if (_stackTrace != null)
			return _stackTrace;

		StackTraceElement[] ste = getStackTrace();
		StringBuilder builder = new StringBuilder();
		if (ste != null) {
			for (int i = 0; i < ste.length; i++) {
				if (builder.length() > 0)
					builder.append(" ");
				builder.append(ste[i].toString());
			}
		}
		return builder.toString();
	}
808630
public static String captureStackTrace(Throwable e) {
        StringWriter buffer = new StringWriter();
        e.printStackTrace(new PrintWriter(buffer));
        return buffer.toString();
    }
1243451
private void setStackTrace(Throwable e) {
        // Convert stack trace to a String
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        stackTrace = sw.toString();
        setLineSeparator(getLineSeparatorProperty());
    }
225532
private static StackLine getStackLine(
            TestMethodTable table, String classQualifiedName, String methodSimpleName, int line) {
        if (line <= 0) {
            return null; // 0 or negative line number never matches
        }
        List<TestMethod> nameMethods = table.getByName(classQualifiedName, methodSimpleName);
        for (TestMethod method : nameMethods) {
            for (int i = 0; i < method.getCodeBody().size(); i++) {
                CodeLine codeLine = method.getCodeBody().get(i);
                if (codeLine.getStartLine() <= line && line <= codeLine.getEndLine()) {
                    StackLine result = new StackLine();
                    result.setMethodKey(method.getKey());
                    result.setMethod(method);
                    result.setCodeBodyIndex(i);
                    result.setLine(line);
                    return result;
                }
            }
        }
        return null;
    }
419121
@Override
    public void printStack(final StringBuilder sb, final StackTraceElement[] trace) {
        for (final StackTraceElement element : trace) {
            sb.append("\tat ").append(element).append('\n');
        }
    }
718319
public static String getStackTrace(Throwable throwable, boolean isHtmlStyle) {
        AssertHelper.notNull(throwable, "throwable can't be null.");
        String line = isHtmlStyle ? "<br/>" : "\r\n";
        String tab = isHtmlStyle ? "&nbsp;&nbsp;&nbsp;&nbsp;" : "\t";
        while (throwable instanceof NiubiException) {
            throwable = throwable.getCause();
        }
        StringBuffer stringBuffer = new StringBuffer(throwable.getClass().getName()).append(":");
        if (throwable.getMessage() != null) {
            stringBuffer.append(throwable.getMessage()).append(line);
        } else {
            stringBuffer.append(line);
        }
        try {
            StackTraceElement[] stackElements = throwable.getStackTrace();
            if (stackElements != null) {
                for (int i = 0; i < stackElements.length && i < MAX_STACK_TRACE_DEEP; i++) {
                    stringBuffer.append(tab);
                    stringBuffer.append(stackElements[i].getClassName()).append('.');
                    stringBuffer.append(stackElements[i].getMethodName()).append('(');
                    stringBuffer.append(stackElements[i].getFileName()).append(':');
                    stringBuffer.append(stackElements[i].getLineNumber()).append(')');
                    stringBuffer.append(line);
                }
            }
        } catch (Exception e) {
            //ignored
        }
        if (isHtmlStyle) {
            return stringBuffer.length() > MAX_LENGTH ? (stringBuffer.substring(0, stringBuffer.lastIndexOf(line)) + DEFAULT_END_STRING) : stringBuffer.toString();
        } else {
            return stringBuffer.length() > MAX_LENGTH ? (stringBuffer.substring(0, MAX_LENGTH) + DEFAULT_END_STRING) : stringBuffer.toString();
        }
    }
300513
public static StackTraceElement getMyStackTraceElement () {
		StackTraceElement myStackTraceElement = null;
		
		StackTraceElement[] stackTraceElements = Thread.currentThread ().getStackTrace ();
		if (stackTraceElements != null) {
			if (stackTraceElements.length > 2) {
				myStackTraceElement = stackTraceElements[2];
			}
		}

		return myStackTraceElement;
	}
451712
public String getStackTraceInfo(Throwable aThrowable) {
        final Writer localWriter = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(localWriter);
        aThrowable.printStackTrace(printWriter);
        return localWriter.toString();
    }