Commit bf642ff9 authored by Andy Wilkinson's avatar Andy Wilkinson

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
parent 7298b2dc
...@@ -115,11 +115,16 @@ public final class FailureAnalyzers { ...@@ -115,11 +115,16 @@ public final class FailureAnalyzers {
private FailureAnalysis analyze(Throwable failure, List<FailureAnalyzer> analyzers) { private FailureAnalysis analyze(Throwable failure, List<FailureAnalyzer> analyzers) {
for (FailureAnalyzer analyzer : analyzers) { for (FailureAnalyzer analyzer : analyzers) {
try {
FailureAnalysis analysis = analyzer.analyze(failure); FailureAnalysis analysis = analyzer.analyze(failure);
if (analysis != null) { if (analysis != null) {
return analysis; return analysis;
} }
} }
catch (Throwable ex) {
log.debug("FailureAnalyzer " + analyzer + " failed", ex);
}
}
return null; return null;
} }
......
...@@ -62,9 +62,16 @@ public class FailureAnalyzersTests { ...@@ -62,9 +62,16 @@ public class FailureAnalyzersTests {
} }
@Test @Test
public void brokenAnalyzerDoesNotPreventOtherAnalyzersFromBeingCalled() { public void analyzerThatFailsDuringInitializationDoesNotPreventOtherAnalyzersFromBeingCalled() {
RuntimeException failure = new RuntimeException(); 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); verify(failureAnalyzer, times(1)).analyze(failure);
} }
...@@ -83,7 +90,7 @@ public class FailureAnalyzersTests { ...@@ -83,7 +90,7 @@ public class FailureAnalyzersTests {
} }
static class BrokenFailureAnalyzer implements FailureAnalyzer { static class BrokenInitializationFailureAnalyzer implements FailureAnalyzer {
static { static {
Object foo = null; Object foo = null;
...@@ -97,6 +104,15 @@ public class FailureAnalyzersTests { ...@@ -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 { interface BeanFactoryAwareFailureAnalyzer extends BeanFactoryAware, FailureAnalyzer {
} }
......
# Failure Analyzers # Failure Analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\ org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.diagnostics.FailureAnalyzersTests$BrokenFailureAnalyzer,\ org.springframework.boot.diagnostics.FailureAnalyzersTests$BrokenAnalysisFailureAnalyzer,\
org.springframework.boot.diagnostics.FailureAnalyzersTests$BasicFailureAnalyzer org.springframework.boot.diagnostics.FailureAnalyzersTests$BasicFailureAnalyzer
# Failure Analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.diagnostics.FailureAnalyzersTests$BrokenAnalysisFailureAnalyzer,\
org.springframework.boot.diagnostics.FailureAnalyzersTests$BasicFailureAnalyzer
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment