AbstractInjectionFailureAnalyzer Class — spring-boot Architecture
Architecture documentation for the AbstractInjectionFailureAnalyzer class in AbstractInjectionFailureAnalyzer.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/AbstractInjectionFailureAnalyzer.java lines 41–120
public abstract class AbstractInjectionFailureAnalyzer<T extends Throwable> extends AbstractFailureAnalyzer<T> {
@Override
protected final @Nullable FailureAnalysis analyze(Throwable rootFailure, T cause) {
return analyze(rootFailure, cause, getDescription(rootFailure));
}
private @Nullable String getDescription(Throwable rootFailure) {
UnsatisfiedDependencyException unsatisfiedDependency = findMostNestedCause(rootFailure,
UnsatisfiedDependencyException.class);
if (unsatisfiedDependency != null) {
return getDescription(unsatisfiedDependency);
}
BeanInstantiationException beanInstantiationException = findMostNestedCause(rootFailure,
BeanInstantiationException.class);
if (beanInstantiationException != null) {
return getDescription(beanInstantiationException);
}
return null;
}
@SuppressWarnings("unchecked")
private <C extends Exception> @Nullable C findMostNestedCause(Throwable root, Class<C> type) {
Throwable candidate = root;
C result = null;
while (candidate != null) {
if (type.isAssignableFrom(candidate.getClass())) {
result = (C) candidate;
}
candidate = candidate.getCause();
}
return result;
}
private @Nullable String getDescription(UnsatisfiedDependencyException ex) {
InjectionPoint injectionPoint = ex.getInjectionPoint();
if (injectionPoint != null) {
if (injectionPoint.getField() != null) {
return String.format("Field %s in %s", injectionPoint.getField().getName(),
injectionPoint.getField().getDeclaringClass().getName());
}
if (injectionPoint.getMethodParameter() != null) {
if (injectionPoint.getMethodParameter().getConstructor() != null) {
return String.format("Parameter %d of constructor in %s",
injectionPoint.getMethodParameter().getParameterIndex(),
injectionPoint.getMethodParameter().getDeclaringClass().getName());
}
Method method = injectionPoint.getMethodParameter().getMethod();
Assert.state(method != null, "Neither constructor nor method is available");
return String.format("Parameter %d of method %s in %s",
injectionPoint.getMethodParameter().getParameterIndex(), method.getName(),
injectionPoint.getMethodParameter().getDeclaringClass().getName());
}
}
return ex.getResourceDescription();
}
private String getDescription(BeanInstantiationException ex) {
if (ex.getConstructingMethod() != null) {
return String.format("Method %s in %s", ex.getConstructingMethod().getName(),
ex.getConstructingMethod().getDeclaringClass().getName());
}
if (ex.getConstructor() != null) {
return String.format("Constructor in %s",
ClassUtils.getUserClass(ex.getConstructor().getDeclaringClass()).getName());
}
return ex.getBeanClass().getName();
}
/**
* Returns an analysis of the given {@code rootFailure}, or {@code null} if no
* analysis was possible.
* @param rootFailure the root failure passed to the analyzer
* @param cause the actual found cause
* @param description the description of the injection point or {@code null}
* @return the analysis or {@code null}
*/
protected abstract @Nullable FailureAnalysis analyze(Throwable rootFailure, T cause, @Nullable String description);
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free