From b34c268547cd7920273eed4d4620fd62a8af45a9 Mon Sep 17 00:00:00 2001 From: im47cn <67424112+im47cn@users.noreply.github.com> Date: Sun, 28 Jun 2020 10:41:10 +0800 Subject: [PATCH] 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 --- .../boot/actuate/metrics/web/tomcat/TomcatMetricsBinder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/tomcat/TomcatMetricsBinder.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/tomcat/TomcatMetricsBinder.java index 688692ff79..1e065eb460 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/tomcat/TomcatMetricsBinder.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/tomcat/TomcatMetricsBinder.java @@ -86,7 +86,9 @@ public class TomcatMetricsBinder implements ApplicationListener