From e4618cfb8d2f1a7452831891be2c7fd190d72e13 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 24 Dec 2020 09:33:48 +0100 Subject: [PATCH] Delete ErrorProperties.IncludeStacktrace Closes gh-21286 --- .../web/servlet/ManagementErrorEndpoint.java | 2 -- .../servlet/ManagementErrorEndpointTests.java | 8 ++--- .../autoconfigure/web/ErrorProperties.java | 34 ++----------------- .../TomcatWebServerFactoryCustomizer.java | 4 +-- .../DefaultErrorWebExceptionHandler.java | 2 -- .../servlet/error/BasicErrorController.java | 2 -- .../BasicErrorControllerIntegrationTests.java | 7 ---- .../DevToolPropertiesIntegrationTests.java | 2 +- 8 files changed, 10 insertions(+), 51 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpoint.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpoint.java index d57ee3cc85..2050b1b52a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpoint.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpoint.java @@ -75,13 +75,11 @@ public class ManagementErrorEndpoint { return options; } - @SuppressWarnings("deprecation") private boolean includeStackTrace(ServletWebRequest request) { switch (this.errorProperties.getIncludeStacktrace()) { case ALWAYS: return true; case ON_PARAM: - case ON_TRACE_PARAM: return getBooleanParameter(request, "trace"); default: return false; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpointTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpointTests.java index b58bcba7cb..c72b31655b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpointTests.java @@ -61,7 +61,7 @@ class ManagementErrorEndpointTests { @Test void errorResponseAlwaysDetails() { - this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ALWAYS); + this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ALWAYS); this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ALWAYS); this.request.addParameter("trace", "false"); this.request.addParameter("message", "false"); @@ -74,7 +74,7 @@ class ManagementErrorEndpointTests { @Test void errorResponseParamsAbsent() { - this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ON_PARAM); + this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ON_PARAM); this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM); ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(this.errorAttributes, this.errorProperties); Map response = endpoint.invoke(new ServletWebRequest(this.request)); @@ -84,7 +84,7 @@ class ManagementErrorEndpointTests { @Test void errorResponseParamsTrue() { - this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ON_PARAM); + this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ON_PARAM); this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM); this.request.addParameter("trace", "true"); this.request.addParameter("message", "true"); @@ -97,7 +97,7 @@ class ManagementErrorEndpointTests { @Test void errorResponseParamsFalse() { - this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ON_PARAM); + this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ON_PARAM); this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM); this.request.addParameter("trace", "false"); this.request.addParameter("message", "false"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java index a2a7b08344..811c113cc6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java @@ -43,7 +43,7 @@ public class ErrorProperties { /** * When to include the "trace" attribute. */ - private IncludeStacktrace includeStacktrace = IncludeStacktrace.NEVER; + private IncludeAttribute includeStacktrace = IncludeAttribute.NEVER; /** * When to include "message" attribute. @@ -73,11 +73,11 @@ public class ErrorProperties { this.includeException = includeException; } - public IncludeStacktrace getIncludeStacktrace() { + public IncludeAttribute getIncludeStacktrace() { return this.includeStacktrace; } - public void setIncludeStacktrace(IncludeStacktrace includeStacktrace) { + public void setIncludeStacktrace(IncludeAttribute includeStacktrace) { this.includeStacktrace = includeStacktrace; } @@ -101,34 +101,6 @@ public class ErrorProperties { return this.whitelabel; } - /** - * Include Stacktrace attribute options. - */ - public enum IncludeStacktrace { - - /** - * Never add stacktrace information. - */ - NEVER, - - /** - * Always add stacktrace information. - */ - ALWAYS, - - /** - * Add error attribute when the appropriate request parameter is "true". - */ - ON_PARAM, - - /** - * Add stacktrace information when the "trace" request parameter is "true". - */ - @Deprecated // since 2.3.0 in favor of {@link #ON_PARAM} - ON_TRACE_PARAM; - - } - /** * Include error attributes options. */ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java index 2c5b618708..0aa4510f3b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java @@ -29,7 +29,7 @@ import org.apache.coyote.ProtocolHandler; import org.apache.coyote.http11.AbstractHttp11Protocol; import org.springframework.boot.autoconfigure.web.ErrorProperties; -import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace; +import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog; import org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Remoteip; @@ -292,7 +292,7 @@ public class TomcatWebServerFactoryCustomizer } private void customizeErrorReportValve(ErrorProperties error, ConfigurableTomcatWebServerFactory factory) { - if (error.getIncludeStacktrace() == IncludeStacktrace.NEVER) { + if (error.getIncludeStacktrace() == IncludeAttribute.NEVER) { factory.addContextCustomizers((context) -> { ErrorReportValve valve = new ErrorReportValve(); valve.setShowServerInfo(false); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java index 772ddc555b..8b31e949b2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java @@ -187,13 +187,11 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa * @param produces the media type produced (or {@code MediaType.ALL}) * @return if the stacktrace attribute should be included */ - @SuppressWarnings("deprecation") protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces) { switch (this.errorProperties.getIncludeStacktrace()) { case ALWAYS: return true; case ON_PARAM: - case ON_TRACE_PARAM: return isTraceEnabled(request); default: return false; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java index a431d079d7..e9bd4c30b0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java @@ -136,13 +136,11 @@ public class BasicErrorController extends AbstractErrorController { * @param produces the media type produced (or {@code MediaType.ALL}) * @return if the stacktrace attribute should be included */ - @SuppressWarnings("deprecation") protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) { switch (getErrorProperties().getIncludeStacktrace()) { case ALWAYS: return true; case ON_PARAM: - case ON_TRACE_PARAM: return getTraceParameter(request); default: return false; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java index bc3bb180a2..3535b1e741 100755 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java @@ -93,13 +93,6 @@ class BasicErrorControllerIntegrationTests { assertThat(entity.getBody().containsKey("trace")).isFalse(); } - @Test - void testErrorForMachineClientWithTraceParamsTrue() { - load("--server.error.include-exception=true", "--server.error.include-stacktrace=on-trace-param", - "--server.error.include-message=on-param"); - exceptionWithStackTraceAndMessage("?trace=true&message=true"); - } - @Test void testErrorForMachineClientWithParamsTrue() { load("--server.error.include-exception=true", "--server.error.include-stacktrace=on-param", diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java index 6c76cfa766..6d470935a1 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java @@ -107,7 +107,7 @@ class DevToolPropertiesIntegrationTests { this.context = getContext(application::run); ConfigurableEnvironment environment = this.context.getEnvironment(); String includeStackTrace = environment.getProperty("server.error.include-stacktrace"); - assertThat(includeStackTrace).isEqualTo(ErrorProperties.IncludeStacktrace.ALWAYS.toString()); + assertThat(includeStackTrace).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString()); String includeMessage = environment.getProperty("server.error.include-message"); assertThat(includeMessage).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString()); }