Class LocationImpl

  • All Implemented Interfaces:
    java.io.Serializable, Location

    class LocationImpl
    extends java.lang.Object
    implements Location, java.io.Serializable
    • Field Detail

      • UNEXPECTED_ERROR_SUFFIX

        private static final java.lang.String UNEXPECTED_ERROR_SUFFIX
        See Also:
        Constant Field Values
      • 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:
        Constant Field Values
      • toStackFrameMetadata

        private static final java.util.function.Function<java.lang.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.
      • FRAMES_TO_SKIP

        private static final int FRAMES_TO_SKIP
      • stackTraceLine

        private volatile java.lang.String stackTraceLine
    • Constructor Detail

      • LocationImpl

        LocationImpl​(boolean isInline)
    • Method Detail

      • getSourceFile

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

        public java.lang.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 java.lang.Object
        Returns:
        location
      • stackTraceLine

        private java.lang.String stackTraceLine()
      • usingDefaultStackTraceCleaner

        private static boolean usingDefaultStackTraceCleaner()
      • noStackTraceFailureMessage

        private static java.lang.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.