From 33288493aa9191b3b784deac268a6fe1c4ffb73b Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 6 Feb 2023 10:03:25 +0100 Subject: [PATCH] Remove exception field from Health class Closes gh-34030 --- .../health/AbstractReactiveHealthIndicator.java | 9 +++++---- .../springframework/boot/actuate/health/Health.java | 13 +------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java index e8e52d29755..4e9269af24a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java @@ -76,14 +76,14 @@ public abstract class AbstractReactiveHealthIndicator implements ReactiveHealthI @Override public final Mono health() { - Mono result; try { - result = doHealthCheck(new Health.Builder()).onErrorResume(this::handleFailure); + Health.Builder builder = new Health.Builder(); + Mono result = doHealthCheck(builder).onErrorResume(this::handleFailure); + return result.doOnNext((health) -> logExceptionIfPresent(builder.getException())); } catch (Exception ex) { - result = handleFailure(ex); + return handleFailure(ex); } - return result.doOnNext((health) -> logExceptionIfPresent(health.getException())); } private void logExceptionIfPresent(Throwable ex) { @@ -94,6 +94,7 @@ public abstract class AbstractReactiveHealthIndicator implements ReactiveHealthI } private Mono handleFailure(Throwable ex) { + logExceptionIfPresent(ex); return Mono.just(new Health.Builder().down(ex).build()); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/Health.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/Health.java index 5d81279ae49..f31952d5262 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/Health.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/Health.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -47,7 +46,6 @@ import org.springframework.util.Assert; * @author Christian Dupuis * @author Phillip Webb * @author Michael Pratt - * @author Moritz Halbritter * @since 1.1.0 */ @JsonInclude(Include.NON_EMPTY) @@ -57,8 +55,6 @@ public final class Health extends HealthComponent { private final Map details; - private final Throwable exception; - /** * Create a new {@link Health} instance with the specified status and details. * @param builder the Builder to use @@ -67,13 +63,11 @@ public final class Health extends HealthComponent { Assert.notNull(builder, "Builder must not be null"); this.status = builder.status; this.details = Collections.unmodifiableMap(builder.details); - this.exception = builder.exception; } Health(Status status, Map details) { this.status = status; this.details = details; - this.exception = null; } /** @@ -107,11 +101,6 @@ public final class Health extends HealthComponent { return status(getStatus()).build(); } - @JsonIgnore - Throwable getException() { - return this.exception; - } - @Override public boolean equals(Object obj) { if (obj == this) { @@ -202,7 +191,7 @@ public final class Health extends HealthComponent { private Status status; - private Map details; + private final Map details; private Throwable exception;