Package com.google.common.truth
Class StackTraceCleaner
java.lang.Object
com.google.common.truth.StackTraceCleaner
Utility that cleans stack traces to remove noise from common frameworks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumEnum of the package or class-name based categories of stack frames that might be removed or collapsed by the cleaner.private static classWrapper around aStackTraceElementfor calculating and holding the metadata used to clean the stack trace. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<StackTraceCleaner.StackTraceElementWrapper> (package private) static final Stringprivate intprivate StackTraceCleaner.StackFrameTypeprivate static final com.google.common.collect.ImmutableSet<Class<?>> private static final com.google.common.collect.ImmutableSet<Class<?>> private static final com.google.common.collect.ImmutableSet<Class<?>> private final Throwable -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateStackTraceCleaner(Throwable throwable) A new instance is instantiated for each throwable to be cleaned. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddToStreak(StackTraceCleaner.StackTraceElementWrapper stackTraceElementWrapper) Either adds the given frame to the running streak or closes out the running streak and starts a new one.private voidCleans the stack trace onthrowable, replacing the trace that was originally on it.(package private) static voidcleanStackTrace(Throwable throwable) CallPlatform.cleanStackTrace(java.lang.Throwable)rather than calling this directly.private voidResets the streak counter.private static StackTraceCleaner.StackTraceElementWrappercreateStreakReplacementFrame(StackTraceCleaner.StackFrameType stackFrameType, int length) private voidEnds the current streak, adding a summary frame to the result.private static booleanisFromClassDirectly(StackTraceElement stackTraceElement, com.google.common.collect.ImmutableSet<Class<?>> recognizedClasses) private static booleanisFromClassOrClassNestedInside(StackTraceElement stackTraceElement, com.google.common.collect.ImmutableSet<Class<?>> recognizedClasses) private static booleanisJUnitIntrastructure(StackTraceElement stackTraceElement) private static booleanReturns true if stack trace cleaning is explicitly disabled in a system property.private static booleanisTruthEntrance(StackTraceElement stackTraceElement) private static Class<?>
-
Field Details
-
CLEANER_LINK
- See Also:
-
throwable
-
cleanedStackTrace
-
lastStackFrameElementWrapper
-
currentStreakType
-
currentStreakLength
private int currentStreakLength -
SUBJECT_CLASS
-
STANDARD_SUBJECT_BUILDER_CLASS
private static final com.google.common.collect.ImmutableSet<Class<?>> STANDARD_SUBJECT_BUILDER_CLASS -
JUNIT_INFRASTRUCTURE_CLASSES
-
-
Constructor Details
-
StackTraceCleaner
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
CallPlatform.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 (seeThrowable.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
Cleans the stack trace onthrowable, replacing the trace that was originally on it. -
addToStreak
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
-
isJUnitIntrastructure
-
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
- 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.
-