Check for null before trying to use ApplicationContext

Fixes gh-145
This commit is contained in:
Dave Syer 2013-12-05 08:54:13 +00:00
parent 33c38b3a51
commit f57c8f52bf
2 changed files with 11 additions and 0 deletions

View File

@ -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());
}

View File

@ -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 {