mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Check for null before trying to use ApplicationContext
Fixes gh-145
This commit is contained in:
parent
33c38b3a51
commit
f57c8f52bf
@ -87,6 +87,10 @@ public class AutoConfigurationReportLoggingInitializer implements
|
||||
|
||||
public void logAutoConfigurationReport(boolean isCrashReport) {
|
||||
if (this.report == null) {
|
||||
if (this.applicationContext == null) {
|
||||
this.logger.info("Nothing to report: ApplicationContext not available");
|
||||
return;
|
||||
}
|
||||
this.report = AutoConfigurationReport.get(this.applicationContext
|
||||
.getBeanFactory());
|
||||
}
|
||||
|
@ -162,6 +162,13 @@ public class AutoConfigurationReportLoggingInitializerTests {
|
||||
assertNotNull(context.getBean(AutoConfigurationReport.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noErrorIfNotInitialized() throws Exception {
|
||||
this.initializer.handleError(null, null, new String[0], new RuntimeException(
|
||||
"Planned"));
|
||||
assertThat(this.infoLog.get(0), containsString("Nothing to report"));
|
||||
}
|
||||
|
||||
public static class MockLogFactory extends LogFactoryImpl {
|
||||
@Override
|
||||
public Log getInstance(String name) throws LogConfigurationException {
|
||||
|
Loading…
Reference in New Issue
Block a user