Package com.helger.base.rt
Class StackTraceHelper
java.lang.Object
com.helger.base.rt.StackTraceHelper
This class contains utility methods for handling stack traces.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringthe separator used to separate different lines of a stack -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendStackToString(@NonNull StringBuilder aSB, @NonNull StackTraceElement[] aStackTraceElements) Append the stack trace of the given elements to the providedStringBuilder, using the default line separator.static voidappendStackToString(@NonNull StringBuilder aSB, @NonNull StackTraceElement[] aStackTraceElements, @NonNull String sLineSeparator) Append the stack trace of the given elements to the providedStringBuilder, using the specified line separator.static booleancontainsUnitTestElement(@Nullable StackTraceElement[] aStackTrace) Check if the passed stack trace array contains a unit test element.static booleancontainsUnitTestElement(@Nullable Throwable t) Check if the passed stack trace array contains a unit test element.static @NonNull StringGet the stack trace of the current thread as a single string, omitting common stack trace elements and using the default line separator.static @NonNull StringgetStackAsString(@NonNull StackTraceElement[] aStackTraceElements) Get the stack trace elements as a single string, omitting common stack trace elements and using the default line separator.static @NonNull StringgetStackAsString(@NonNull StackTraceElement[] aStackTraceElements, boolean bOmitCommonStackTraceElements) Get the stack trace elements as a single string.static @NonNull StringgetStackAsString(@NonNull StackTraceElement[] aStackTraceElements, boolean bOmitCommonStackTraceElements, @NonNull String sLineSeparator) Get the stack trace elements as a single string, using a custom line separator.static @NonNull StringgetStackAsString(@NonNull Thread aThread) Get the stack trace of the passed thread as a single string, omitting common stack trace elements and using the default line separator.static @NonNull StringgetStackAsString(@NonNull Thread aThread, boolean bOmitCommonStackTraceElements) Get the stack trace of the passed thread as a single string, using the default line separator.static @NonNull StringgetStackAsString(@NonNull Thread aThread, boolean bOmitCommonStackTraceElements, @NonNull String sLineSeparator) Get the stack trace of the passed thread as a single string, using a custom line separator.static @NonNull StringgetStackAsString(@Nullable Throwable t) Get the stack trace of a throwable as string.static @NonNull StringgetStackAsString(@Nullable Throwable t, boolean bOmitCommonStackTraceElements) Get the stack trace of a throwable as string.static @NonNull StringgetStackAsString(@Nullable Throwable t, boolean bOmitCommonStackTraceElements, @NonNull String sLineSeparator) Get the stack trace of a throwable as string.
-
Field Details
-
DEFAULT_LINE_SEPARATOR
the separator used to separate different lines of a stack- See Also:
-
-
Method Details
-
appendStackToString
public static void appendStackToString(@NonNull StringBuilder aSB, @NonNull StackTraceElement[] aStackTraceElements) Append the stack trace of the given elements to the providedStringBuilder, using the default line separator.- Parameters:
aSB- The StringBuilder to append to. May not benull.aStackTraceElements- The stack trace elements to append. May not benull.
-
appendStackToString
public static void appendStackToString(@NonNull StringBuilder aSB, @NonNull StackTraceElement[] aStackTraceElements, @NonNull String sLineSeparator) Append the stack trace of the given elements to the providedStringBuilder, using the specified line separator.- Parameters:
aSB- The StringBuilder to append to. May not benull.aStackTraceElements- The stack trace elements to append. May not benull.sLineSeparator- The line separator to use. May not benull.
-
getStackAsString
public static @NonNull String getStackAsString(@NonNull StackTraceElement[] aStackTraceElements, boolean bOmitCommonStackTraceElements) Get the stack trace elements as a single string.- Parameters:
aStackTraceElements- The stack trace elements to convert. May not benull.bOmitCommonStackTraceElements- Iftruethe stack trace is cut after certain class names occurring. Iffalsethe complete stack trace is returned.- Returns:
- The stack trace as a string. Never
null.
-
getStackAsString
public static @NonNull String getStackAsString(@NonNull StackTraceElement[] aStackTraceElements, boolean bOmitCommonStackTraceElements, @NonNull String sLineSeparator) Get the stack trace elements as a single string, using a custom line separator.- Parameters:
aStackTraceElements- The stack trace elements to convert. May not benull.bOmitCommonStackTraceElements- Iftruethe stack trace is cut after certain class names occurring. Iffalsethe complete stack trace is returned.sLineSeparator- The line separator to use. May not benull.- Returns:
- The stack trace as a string. Never
null.
-
getStackAsString
Get the stack trace elements as a single string, omitting common stack trace elements and using the default line separator.- Parameters:
aStackTraceElements- The stack trace elements to convert. May not benull.- Returns:
- The stack trace as a string. Never
null.
-
getStackAsString
Get the stack trace of the passed thread as a single string, omitting common stack trace elements and using the default line separator.- Parameters:
aThread- The thread whose stack trace is to be converted. May not benull.- Returns:
- The stack trace as a string. Never
null.
-
getStackAsString
public static @NonNull String getStackAsString(@NonNull Thread aThread, boolean bOmitCommonStackTraceElements) Get the stack trace of the passed thread as a single string, using the default line separator.- Parameters:
aThread- The thread whose stack trace is to be converted. May not benull.bOmitCommonStackTraceElements- Iftruethe stack trace is cut after certain class names occurring. Iffalsethe complete stack trace is returned.- Returns:
- The stack trace as a string. Never
null.
-
getStackAsString
public static @NonNull String getStackAsString(@NonNull Thread aThread, boolean bOmitCommonStackTraceElements, @NonNull String sLineSeparator) Get the stack trace of the passed thread as a single string, using a custom line separator.- Parameters:
aThread- The thread whose stack trace is to be converted. May not benull.bOmitCommonStackTraceElements- Iftruethe stack trace is cut after certain class names occurring. Iffalsethe complete stack trace is returned.sLineSeparator- The line separator to use. May not benull.- Returns:
- The stack trace as a string. Never
null.
-
getCurrentThreadStackAsString
Get the stack trace of the current thread as a single string, omitting common stack trace elements and using the default line separator.- Returns:
- The current thread's stack trace as a string. Never
null.
-
getStackAsString
Get the stack trace of a throwable as string.- Parameters:
t- The throwable to be converted. May benull.- Returns:
- the stack trace as newline separated string. If the passed Throwable is
nullan empty string is returned.
-
getStackAsString
public static @NonNull String getStackAsString(@Nullable Throwable t, boolean bOmitCommonStackTraceElements) Get the stack trace of a throwable as string.- Parameters:
t- The throwable to be converted. May benull.bOmitCommonStackTraceElements- Iftruethe stack trace is cut after certain class names occurring. Iffalsethe complete stack trace is returned.- Returns:
- the stack trace as newline separated string. If the passed Throwable is
nullan empty string is returned.
-
getStackAsString
public static @NonNull String getStackAsString(@Nullable Throwable t, boolean bOmitCommonStackTraceElements, @NonNull String sLineSeparator) Get the stack trace of a throwable as string.- Parameters:
t- The throwable to be converted. May benull.bOmitCommonStackTraceElements- Iftruethe stack trace is cut after certain class names occurring. Iffalsethe complete stack trace is returned.sLineSeparator- The line separator to use. May not benull.- Returns:
- the stack trace as newline separated string. If the passed Throwable is
nullan empty string is returned. - Since:
- 9.3.6
-
containsUnitTestElement
Check if the passed stack trace array contains a unit test element. Known unit test frameworks are JUnit and TestNG.- Parameters:
t- TheThrowablewhose stack trace should be scanned for unit test classes. May benull.- Returns:
trueif at least one stack trace element is from a known unit test framework.
-
containsUnitTestElement
Check if the passed stack trace array contains a unit test element. Known unit test frameworks are JUnit and TestNG.- Parameters:
aStackTrace- The stack trace array to be scanned. May benull.- Returns:
trueif at least one stack trace element is from a known unit test framework.
-