Continue failure analysis when an analyzer throws an exception
Previously, if a failure analyzer threw an exception from its analyze method, failure analysis would stop. This commit updates FailureAnalyzers to catch and log any Throwable thrown by an analyzer and continue to the next available analyzer. Closes gh-7956
This commit is contained in:
parent
7298b2dc1b
commit
bf642ff9db
|
|
@ -115,9 +115,14 @@ public final class FailureAnalyzers {
|
|||
|
||||
private FailureAnalysis analyze(Throwable failure, List<FailureAnalyzer> analyzers) {
|
||||
for (FailureAnalyzer analyzer : analyzers) {
|
||||
FailureAnalysis analysis = analyzer.analyze(failure);
|
||||
if (analysis != null) {
|
||||
return analysis;
|
||||
try {
|
||||
FailureAnalysis analysis = analyzer.analyze(failure);
|
||||
if (analysis != null) {
|
||||
return analysis;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
log.debug("FailureAnalyzer " + analyzer + " failed", ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -62,9 +62,16 @@ public class FailureAnalyzersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void brokenAnalyzerDoesNotPreventOtherAnalyzersFromBeingCalled() {
|
||||
public void analyzerThatFailsDuringInitializationDoesNotPreventOtherAnalyzersFromBeingCalled() {
|
||||
RuntimeException failure = new RuntimeException();
|
||||
analyzeAndReport("broken.factories", failure);
|
||||
analyzeAndReport("broken-initialization.factories", failure);
|
||||
verify(failureAnalyzer, times(1)).analyze(failure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void analyzerThatFailsDuringAnalysisDoesNotPreventOtherAnalyzersFromBeingCalled() {
|
||||
RuntimeException failure = new RuntimeException();
|
||||
analyzeAndReport("broken-analysis.factories", failure);
|
||||
verify(failureAnalyzer, times(1)).analyze(failure);
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +90,7 @@ public class FailureAnalyzersTests {
|
|||
|
||||
}
|
||||
|
||||
static class BrokenFailureAnalyzer implements FailureAnalyzer {
|
||||
static class BrokenInitializationFailureAnalyzer implements FailureAnalyzer {
|
||||
|
||||
static {
|
||||
Object foo = null;
|
||||
|
|
@ -97,6 +104,15 @@ public class FailureAnalyzersTests {
|
|||
|
||||
}
|
||||
|
||||
static class BrokenAnalysisFailureAnalyzer implements FailureAnalyzer {
|
||||
|
||||
@Override
|
||||
public FailureAnalysis analyze(Throwable failure) {
|
||||
throw new NoClassDefFoundError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface BeanFactoryAwareFailureAnalyzer extends BeanFactoryAware, FailureAnalyzer {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Failure Analyzers
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
org.springframework.boot.diagnostics.FailureAnalyzersTests$BrokenFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.FailureAnalyzersTests$BrokenAnalysisFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.FailureAnalyzersTests$BasicFailureAnalyzer
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# Failure Analyzers
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
org.springframework.boot.diagnostics.FailureAnalyzersTests$BrokenAnalysisFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.FailureAnalyzersTests$BasicFailureAnalyzer
|
||||
Loading…
Reference in New Issue