Avoid NPE when binder is closed before started event

Previously, if TomcatMetricsBinder destroy() was called before it had
received an ApplicationStartedEvent an NPE would be thrown due to
TomcatMetrics being null. This NPE was then caught and logged at
warning level by the disposable bean adapter.

This prevents the NPE by checking that the TomcatMetrics instance is
null before calling close() on it.

See gh-22141
pull/23053/head
im47cn 4 years ago committed by Andy Wilkinson
parent 9c732fa2b6
commit b34c268547

@ -86,7 +86,9 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart
@Override
public void destroy() {
this.tomcatMetrics.close();
if (null != this.tomcatMetrics) {
this.tomcatMetrics.close();
}
}
}

Loading…
Cancel
Save