Class LocationImpl

java.lang.Object
org.mockito.internal.debugging.LocationImpl
All Implemented Interfaces:
Serializable, Location

class LocationImpl extends Object implements Location, Serializable
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • UNEXPECTED_ERROR_SUFFIX

      private static final String UNEXPECTED_ERROR_SUFFIX
      See Also:
    • BUFFER_SIZE

      private static final int BUFFER_SIZE
      This is an unfortunate buffer. Inside StackWalker, a buffer is created, which is resized by doubling. The resizing also allocates a tonne of StackFrame elements. If we traverse more than BUFFER_SIZE elements, the resulting resize can significantly affect the overall cost of the operation. If we traverse fewer than this number, we are inefficient. Empirically, 16 is enough stack frames for a simple stub+call operation to succeed without resizing, as measured on Java 11.
      See Also:
    • PREFIX

      private static final String PREFIX
      See Also:
    • CLEANER

      private static final StackTraceCleaner CLEANER
    • toStackFrameMetadata

      private static final Function<StackTraceElement,StackTraceCleaner.StackFrameMetadata> toStackFrameMetadata
      In Java, allocating lambdas is cheap, but not free. stream.map(this::doSomething) will allocate a Function object each time the function is called (although not per element). By assigning these Functions and Predicates to variables, we can avoid the memory allocation.
    • cleanerIsIn

      private static final Predicate<StackTraceCleaner.StackFrameMetadata> cleanerIsIn
    • FRAMES_TO_SKIP

      private static final int FRAMES_TO_SKIP
    • sfm

    • stackTraceLine

      private volatile String stackTraceLine
  • Constructor Details

    • LocationImpl

      LocationImpl(boolean isInline)
  • Method Details

    • getSourceFile

      public String getSourceFile()
      Description copied from interface: Location
      Source file of this location
      Specified by:
      getSourceFile in interface Location
      Returns:
      source file
    • toString

      public String toString()
      Description copied from interface: Location
      Human readable location in the source code, see Invocation.getLocation()
      Specified by:
      toString in interface Location
      Overrides:
      toString in class Object
      Returns:
      location
    • stackTraceLine

      private String stackTraceLine()
    • getStackFrame

      private static StackTraceCleaner.StackFrameMetadata getStackFrame(boolean isInline)
    • usingDefaultStackTraceCleaner

      private static boolean usingDefaultStackTraceCleaner()
    • noStackTraceFailureMessage

      private static String noStackTraceFailureMessage()
    • framesToSkip

      private static int framesToSkip()
      In order to trigger the stack walker, we create some reflective frames. These need to be skipped so as to ensure there are no non-Mockito frames at the top of the stack trace.