Class StackTraceFilter

java.lang.Object
org.mockito.internal.exceptions.stacktrace.StackTraceFilter
All Implemented Interfaces:
Serializable

public class StackTraceFilter extends Object implements Serializable
See Also:
  • Field Details

    • serialVersionUID

      static final long serialVersionUID
      See Also:
    • CLEANER

      private static final StackTraceCleaner CLEANER
    • JAVA_LANG_ACCESS

      private static Object JAVA_LANG_ACCESS
    • GET_STACK_TRACE_ELEMENT

      private static Method GET_STACK_TRACE_ELEMENT
  • Constructor Details

    • StackTraceFilter

      public StackTraceFilter()
  • Method Details

    • filter

      public StackTraceElement[] filter(StackTraceElement[] target, boolean keepTop)
      Example how the filter works (+/- means good/bad): [a+, b+, c-, d+, e+, f-, g+] -> [a+, b+, d+, e+, g+] Basically removes all bad from the middle. If any good are in the middle of bad those are also removed.
    • filterFirst

      public StackTraceElement filterFirst(Throwable target, boolean isInline)
      This filtering strategy makes use of a fast-path computation to retrieve stackTraceElements from a Stacktrace of a Throwable. It does so, by taking advantage of sun.misc.SharedSecrets and sun.misc.JavaLangAccess.

      The sun.misc.SharedSecrets provides a method to obtain an instance of an sun.misc.JavaLangAccess. The latter class has a method to fast-path into Throwable.getStackTrace() and retrieve a single StackTraceElement. This prevents the JVM from having to generate a full stacktrace, which could potentially be expensive if stacktraces become very large.

      Parameters:
      target - The throwable target to find the first StackTraceElement that should not be filtered out per CLEANER.
      Returns:
      The first StackTraceElement outside of the CLEANER
    • findSourceFile

      public String findSourceFile(StackTraceElement[] target, String defaultValue)
      Finds the source file of the target stack trace. Returns the default value if source file cannot be found.