Class StackTraceCleaner


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

      • throwable

        private final java.lang.Throwable throwable
      • currentStreakLength

        private int currentStreakLength
      • SUBJECT_CLASS

        private static final com.google.common.collect.ImmutableSet<java.lang.Class<?>> SUBJECT_CLASS
      • STANDARD_SUBJECT_BUILDER_CLASS

        private static final com.google.common.collect.ImmutableSet<java.lang.Class<?>> STANDARD_SUBJECT_BUILDER_CLASS
      • JUNIT_INFRASTRUCTURE_CLASSES

        private static final com.google.common.collect.ImmutableSet<java.lang.Class<?>> JUNIT_INFRASTRUCTURE_CLASSES
    • Constructor Detail

      • StackTraceCleaner

        private StackTraceCleaner​(java.lang.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 Detail

      • cleanStackTrace

        static void cleanStackTrace​(java.lang.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​(java.util.Set<java.lang.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​(java.lang.StackTraceElement stackTraceElement)
      • isJUnitIntrastructure

        private static boolean isJUnitIntrastructure​(java.lang.StackTraceElement stackTraceElement)
      • isFromClassOrClassNestedInside

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

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

        private static java.lang.Class<?> loadClass​(java.lang.String name)
                                             throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • 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.