Class ThrowableProxy
java.lang.Object
org.apache.logging.log4j.core.impl.ThrowableProxy
- All Implemented Interfaces:
Serializable
Wraps a Throwable to add packaging information about each stack trace element.
A proxy is used to represent a throwable that may not exist in a different class loader or JVM. When an application deserializes a ThrowableProxy, the throwable may not be set, but the throwable's information is preserved in other fields of the proxy like the message and stack trace.
TODO: Move this class to org.apache.logging.log4j.core because it is used from LogEvent.
TODO: Deserialize: Try to rebuild Throwable if the target exception is in this class loader?
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ThrowableProxy
private int
(package private) static final ThrowableProxy[]
private static final char
private static final String
private final ExtendedStackTraceElement[]
private final String
private final String
private final String
private static final long
private final ThrowableProxy[]
private final Throwable
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
For JSON and XML IO via Jackson.ThrowableProxy
(Throwable throwable) Constructs the wrapper for the Throwable that includes packaging data.private
ThrowableProxy
(Throwable parent, Deque<Class<?>> stack, Map<String, ThrowableProxyHelper.CacheEntry> map, Throwable cause, Set<Throwable> suppressedVisited, Set<Throwable> causeVisited) Constructs the wrapper for a Throwable that is referenced as the cause by another Throwable.(package private)
ThrowableProxy
(Throwable throwable, Set<Throwable> visited) Constructs the wrapper for the Throwable that includes packaging data. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
formatExtendedStackTraceTo
(StringBuilder sb, List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the stack trace including packaging information.void
formatWrapper
(StringBuilder sb, ThrowableProxy cause, String suffix) Formats the specified Throwable.void
formatWrapper
(StringBuilder sb, ThrowableProxy cause, List<String> ignorePackages, String suffix) Formats the specified Throwable.void
formatWrapper
(StringBuilder sb, ThrowableProxy cause, List<String> ignorePackages, TextRenderer textRenderer, String suffix) Formats the specified Throwable.void
formatWrapper
(StringBuilder sb, ThrowableProxy cause, List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the specified Throwable.getCauseStackTraceAsString
(String suffix) Formats the Throwable that is the cause of this Throwable.getCauseStackTraceAsString
(List<String> packages, String suffix) Formats the Throwable that is the cause of this Throwable.getCauseStackTraceAsString
(List<String> ignorePackages, TextRenderer textRenderer, String suffix) Formats the Throwable that is the cause of this Throwable.getCauseStackTraceAsString
(List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the Throwable that is the cause of this Throwable.int
Returns the number of elements that are being omitted because they are common with the parent Throwable's stack trace.Gets the stack trace including packaging information.Formats the stack trace including packaging information.getExtendedStackTraceAsString
(String suffix) Formats the stack trace including packaging information.getExtendedStackTraceAsString
(List<String> ignorePackages, String suffix) Formats the stack trace including packaging information.getExtendedStackTraceAsString
(List<String> ignorePackages, TextRenderer textRenderer, String suffix) Formats the stack trace including packaging information.getExtendedStackTraceAsString
(List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the stack trace including packaging information.getName()
Return the FQCN of the Throwable.Gets proxies for suppressed exceptions.getSuppressedStackTrace
(String suffix) Formats the suppressed Throwables.The throwable or null if this object is deserialized from XML or JSON.int
hashCode()
(package private) void
setCommonElementCount
(int value) Set the value ofcommonElementCount
.toString()
-
Field Details
-
EOL
private static final char EOL- See Also:
-
EOL_STR
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
causeProxy
-
commonElementCount
private int commonElementCount -
extendedStackTrace
-
localizedMessage
-
message
-
name
-
suppressedProxies
-
throwable
-
EMPTY_ARRAY
-
-
Constructor Details
-
ThrowableProxy
ThrowableProxy()For JSON and XML IO via Jackson. -
ThrowableProxy
Constructs the wrapper for the Throwable that includes packaging data.- Parameters:
throwable
- The Throwable to wrap, must not be null.
-
ThrowableProxy
Constructs the wrapper for the Throwable that includes packaging data.- Parameters:
throwable
- The Throwable to wrap, must not be null.visited
- The set of visited suppressed exceptions.
-
ThrowableProxy
private ThrowableProxy(Throwable parent, Deque<Class<?>> stack, Map<String, ThrowableProxyHelper.CacheEntry> map, Throwable cause, Set<Throwable> suppressedVisited, Set<Throwable> causeVisited) Constructs the wrapper for a Throwable that is referenced as the cause by another Throwable.- Parameters:
parent
- The Throwable referencing this Throwable.stack
- The Class stack.map
- The cache containing the packaging data.cause
- The Throwable to wrap.suppressedVisited
- TODOcauseVisited
- TODO
-
-
Method Details
-
equals
-
formatWrapper
Formats the specified Throwable.- Parameters:
sb
- StringBuilder to contain the formatted Throwable.cause
- The Throwable to format.suffix
-
-
formatWrapper
public void formatWrapper(StringBuilder sb, ThrowableProxy cause, List<String> ignorePackages, String suffix) Formats the specified Throwable.- Parameters:
sb
- StringBuilder to contain the formatted Throwable.cause
- The Throwable to format.ignorePackages
- The List of packages to be suppressed from the trace.suffix
-
-
formatWrapper
public void formatWrapper(StringBuilder sb, ThrowableProxy cause, List<String> ignorePackages, TextRenderer textRenderer, String suffix) Formats the specified Throwable.- Parameters:
sb
- StringBuilder to contain the formatted Throwable.cause
- The Throwable to format.ignorePackages
- The List of packages to be suppressed from the stack trace.textRenderer
- The text renderer.suffix
- Append this to the end of each stack frame.
-
formatWrapper
public void formatWrapper(StringBuilder sb, ThrowableProxy cause, List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the specified Throwable.- Parameters:
sb
- StringBuilder to contain the formatted Throwable.cause
- The Throwable to format.ignorePackages
- The List of packages to be suppressed from the stack trace.textRenderer
- The text renderer.suffix
- Append this to the end of each stack frame.lineSeparator
- The end-of-line separator.
-
getCauseProxy
-
getCauseStackTraceAsString
Formats the Throwable that is the cause of this Throwable.- Parameters:
suffix
-- Returns:
- The formatted Throwable that caused this Throwable.
-
getCauseStackTraceAsString
Formats the Throwable that is the cause of this Throwable.- Parameters:
packages
- The List of packages to be suppressed from the trace.suffix
- Append this to the end of each stack frame.- Returns:
- The formatted Throwable that caused this Throwable.
-
getCauseStackTraceAsString
public String getCauseStackTraceAsString(List<String> ignorePackages, TextRenderer textRenderer, String suffix) Formats the Throwable that is the cause of this Throwable.- Parameters:
ignorePackages
- The List of packages to be suppressed from the trace.textRenderer
- The text renderer.suffix
- Append this to the end of each stack frame.- Returns:
- The formatted Throwable that caused this Throwable.
-
getCauseStackTraceAsString
public String getCauseStackTraceAsString(List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the Throwable that is the cause of this Throwable.- Parameters:
ignorePackages
- The List of packages to be suppressed from the stack trace.textRenderer
- The text renderer.suffix
- Append this to the end of each stack frame.lineSeparator
- The end-of-line separator.- Returns:
- The formatted Throwable that caused this Throwable.
-
getCommonElementCount
public int getCommonElementCount()Returns the number of elements that are being omitted because they are common with the parent Throwable's stack trace.- Returns:
- The number of elements omitted from the stack trace.
-
setCommonElementCount
void setCommonElementCount(int value) Set the value ofcommonElementCount
. Method is package-private, to be used internally for initialization.- Parameters:
value
- New value of commonElementCount.
-
getExtendedStackTrace
Gets the stack trace including packaging information.- Returns:
- The stack trace including packaging information.
-
getExtendedStackTraceAsString
Formats the stack trace including packaging information.- Returns:
- The formatted stack trace including packaging information.
-
getExtendedStackTraceAsString
Formats the stack trace including packaging information.- Parameters:
suffix
- Append this to the end of each stack frame.- Returns:
- The formatted stack trace including packaging information.
-
getExtendedStackTraceAsString
Formats the stack trace including packaging information.- Parameters:
ignorePackages
- List of packages to be ignored in the trace.suffix
- Append this to the end of each stack frame.- Returns:
- The formatted stack trace including packaging information.
-
getExtendedStackTraceAsString
public String getExtendedStackTraceAsString(List<String> ignorePackages, TextRenderer textRenderer, String suffix) Formats the stack trace including packaging information.- Parameters:
ignorePackages
- List of packages to be ignored in the trace.textRenderer
- The message renderer.suffix
- Append this to the end of each stack frame.- Returns:
- The formatted stack trace including packaging information.
-
getExtendedStackTraceAsString
public String getExtendedStackTraceAsString(List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the stack trace including packaging information.- Parameters:
ignorePackages
- List of packages to be ignored in the trace.textRenderer
- The message renderer.suffix
- Append this to the end of each stack frame.lineSeparator
- The end-of-line separator.- Returns:
- The formatted stack trace including packaging information.
-
formatExtendedStackTraceTo
public void formatExtendedStackTraceTo(StringBuilder sb, List<String> ignorePackages, TextRenderer textRenderer, String suffix, String lineSeparator) Formats the stack trace including packaging information.- Parameters:
sb
- Destination.ignorePackages
- List of packages to be ignored in the trace.textRenderer
- The message renderer.suffix
- Append this to the end of each stack frame.lineSeparator
- The end-of-line separator.
-
getLocalizedMessage
-
getMessage
-
getName
Return the FQCN of the Throwable.- Returns:
- The FQCN of the Throwable.
-
getStackTrace
-
getSuppressedProxies
Gets proxies for suppressed exceptions.- Returns:
- proxies for suppressed exceptions.
-
getSuppressedStackTrace
Formats the suppressed Throwables.- Parameters:
suffix
-- Returns:
- The formatted suppressed Throwables.
-
getThrowable
The throwable or null if this object is deserialized from XML or JSON.- Returns:
- The throwable or null if this object is deserialized from XML or JSON.
-
hashCode
public int hashCode() -
toString
-