Class ThrowableAnalyzer
java.lang.Object
org.springframework.security.web.util.ThrowableAnalyzer
Handler for analyzing
Throwable
instances.
Can be subclassed to customize its behavior.- Since:
- 2.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ThrowableCauseExtractor
Default extractor forThrowable
instances.static final ThrowableCauseExtractor
Default extractor forInvocationTargetException
instances. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal Throwable[]
determineCauseChain
(Throwable throwable) Determines the cause chain of the providedThrowable
.final Throwable
getFirstThrowableOfType
(Class<? extends Throwable> throwableType, Throwable[] chain) Returns the first throwable from the passed in array that is assignable to the provided type.protected void
Initializes associations betweenThrowable
s andThrowableCauseExtractor
s.protected final void
registerExtractor
(Class<? extends Throwable> throwableType, ThrowableCauseExtractor extractor) Registers aThrowableCauseExtractor
for the specified type.static void
verifyThrowableHierarchy
(Throwable throwable, Class<? extends Throwable> expectedBaseType) Verifies that the provided throwable is a valid subclass of the provided type (or of the type itself).
-
Field Details
-
DEFAULT_EXTRACTOR
Default extractor forThrowable
instances.- See Also:
-
INVOCATIONTARGET_EXTRACTOR
Default extractor forInvocationTargetException
instances.
-
-
Constructor Details
-
ThrowableAnalyzer
public ThrowableAnalyzer()Creates a newThrowableAnalyzer
instance.
-
-
Method Details
-
registerExtractor
protected final void registerExtractor(Class<? extends Throwable> throwableType, ThrowableCauseExtractor extractor) Registers aThrowableCauseExtractor
for the specified type. Can be used in subclasses overridinginitExtractorMap()
.- Parameters:
throwableType
- the type (has to be a subclass ofThrowable
)extractor
- the associatedThrowableCauseExtractor
(notnull
)- Throws:
IllegalArgumentException
- if one of the arguments is invalid
-
initExtractorMap
protected void initExtractorMap()Initializes associations betweenThrowable
s andThrowableCauseExtractor
s. The default implementation performs the following registrations:
Subclasses overriding this method are encouraged to invoke the super method to perform the default registrations. They can register additional extractors as required.Note: An extractor registered for a specific type is applicable for that type and all subtypes thereof. However, extractors registered to more specific types are guaranteed to be resolved first. So in the default case InvocationTargetExceptions will be handled by
INVOCATIONTARGET_EXTRACTOR
while all other throwables are handled byDEFAULT_EXTRACTOR
. -
determineCauseChain
Determines the cause chain of the providedThrowable
. The returned array contains all throwables extracted from the stacktrace, using the registeredextractors
. The elements of the array are ordered: The first element is the passed in throwable itself. The following elements appear in their order downward the stacktrace.Note: If no
ThrowableCauseExtractor
is registered for this instance then the returned array will always only contain the passed in throwable.- Parameters:
throwable
- theThrowable
to analyze- Returns:
- an array of all determined throwables from the stacktrace
- Throws:
IllegalArgumentException
- if the throwable isnull
- See Also:
-
getFirstThrowableOfType
public final Throwable getFirstThrowableOfType(Class<? extends Throwable> throwableType, Throwable[] chain) Returns the first throwable from the passed in array that is assignable to the provided type. A returned instance is safe to be cast to the specified type.If the passed in array is null or empty this method returns
null
.- Parameters:
throwableType
- the type to look forchain
- the array (will be processed in element order)- Returns:
- the found
Throwable
,null
if not found - Throws:
IllegalArgumentException
- if the provided type isnull
or no subclass ofThrowable
-
verifyThrowableHierarchy
public static void verifyThrowableHierarchy(Throwable throwable, Class<? extends Throwable> expectedBaseType) Verifies that the provided throwable is a valid subclass of the provided type (or of the type itself). IfexpectdBaseType
isnull
, no check will be performed.Can be used for verification purposes in implementations of
extractors
.- Parameters:
throwable
- theThrowable
to checkexpectedBaseType
- the type to check against- Throws:
IllegalArgumentException
- ifthrowable
is eithernull
or its type is not assignable toexpectedBaseType
-