Class StackTraceCleaner

java.lang.Object
com.google.common.truth.StackTraceCleaner

final class StackTraceCleaner extends Object
Utility that cleans stack traces to remove noise from common frameworks.
  • Field Details

  • Constructor Details

    • StackTraceCleaner

      private StackTraceCleaner(Throwable throwable)
      A new instance is instantiated for each throwable to be cleaned. This is so that helper methods can make use of instance variables describing the state of the cleaning process.
  • Method Details

    • cleanStackTrace

      static void cleanStackTrace(Throwable throwable)
      Call Platform.cleanStackTrace(java.lang.Throwable) rather than calling this directly.

      Cleans the stack trace on the given Throwable, replacing the original stack trace stored on the instance (see Throwable.setStackTrace(StackTraceElement[])).

      Removes Truth stack frames from the top and JUnit framework and reflective call frames from the bottom. Collapses the frames for various frameworks in the middle of the trace as well.

    • clean

      private void clean(Set<Throwable> seenThrowables)
      Cleans the stack trace on throwable, replacing the trace that was originally on it.
    • addToStreak

      private void addToStreak(StackTraceCleaner.StackTraceElementWrapper stackTraceElementWrapper)
      Either adds the given frame to the running streak or closes out the running streak and starts a new one.
    • endStreak

      private void endStreak()
      Ends the current streak, adding a summary frame to the result. Resets the streak counter.
    • clearStreak

      private void clearStreak()
      Resets the streak counter.
    • isTruthEntrance

      private static boolean isTruthEntrance(StackTraceElement stackTraceElement)
    • isJUnitIntrastructure

      private static boolean isJUnitIntrastructure(StackTraceElement stackTraceElement)
    • isFromClassOrClassNestedInside

      private static boolean isFromClassOrClassNestedInside(StackTraceElement stackTraceElement, com.google.common.collect.ImmutableSet<Class<?>> recognizedClasses)
    • isFromClassDirectly

      private static boolean isFromClassDirectly(StackTraceElement stackTraceElement, com.google.common.collect.ImmutableSet<Class<?>> recognizedClasses)
    • loadClass

      private static Class<?> loadClass(String name) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • createStreakReplacementFrame

      private static StackTraceCleaner.StackTraceElementWrapper createStreakReplacementFrame(StackTraceCleaner.StackFrameType stackFrameType, int length)
    • isStackTraceCleaningDisabled

      private static boolean isStackTraceCleaningDisabled()
      Returns true if stack trace cleaning is explicitly disabled in a system property. This switch is intended to be used when attempting to debug the frameworks which are collapsed or filtered out of stack traces by the cleaner.