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
This commit is contained in:
im47cn 2020-06-28 10:41:10 +08:00 committed by Andy Wilkinson
parent 9c732fa2b6
commit b34c268547

View File

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