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 0dc697ef6cc..a11e090e4ff 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 @@ -55,7 +55,7 @@ class ManagementErrorEndpointTests { void errorResponseNeverDetails() { ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(this.errorAttributes, this.errorProperties); Map response = endpoint.invoke(new ServletWebRequest(new MockHttpServletRequest())); - assertThat(response).containsEntry("message", ""); + assertThat(response).doesNotContainKey("message"); assertThat(response).doesNotContainKey("trace"); } @@ -78,7 +78,7 @@ class ManagementErrorEndpointTests { this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM); ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(this.errorAttributes, this.errorProperties); Map response = endpoint.invoke(new ServletWebRequest(this.request)); - assertThat(response).containsEntry("message", ""); + assertThat(response).doesNotContainKey("message"); assertThat(response).doesNotContainKey("trace"); } @@ -103,7 +103,7 @@ class ManagementErrorEndpointTests { this.request.addParameter("message", "false"); ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(this.errorAttributes, this.errorProperties); Map response = endpoint.invoke(new ServletWebRequest(this.request)); - assertThat(response).containsEntry("message", ""); + assertThat(response).doesNotContainKey("message"); assertThat(response).doesNotContainKey("trace"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java index 08cab75a096..576935cbd70 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java @@ -87,8 +87,8 @@ class DefaultErrorWebExceptionHandlerIntegrationTests { client.get().uri("/").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody() .jsonPath("status").isEqualTo("500").jsonPath("error") .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()).jsonPath("path").isEqualTo(("/")) - .jsonPath("message").isEmpty().jsonPath("exception").doesNotExist().jsonPath("trace").doesNotExist() - .jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId()); + .jsonPath("message").doesNotExist().jsonPath("exception").doesNotExist().jsonPath("trace") + .doesNotExist().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId()); assertThat(output).contains("500 Server Error for HTTP GET \"/\"") .contains("java.lang.IllegalStateException: Expected!"); }); @@ -124,7 +124,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests { .isBadRequest().expectBody().jsonPath("status").isEqualTo("400").jsonPath("error") .isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path").isEqualTo(("/bind")) .jsonPath("exception").doesNotExist().jsonPath("errors").doesNotExist().jsonPath("message") - .isEmpty().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId()); + .doesNotExist().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId()); }); } @@ -227,7 +227,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests { .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody().jsonPath("status") .isEqualTo("500").jsonPath("error") .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()).jsonPath("exception") - .isEqualTo(IllegalStateException.class.getName()).jsonPath("message").isEmpty() + .isEqualTo(IllegalStateException.class.getName()).jsonPath("message").doesNotExist() .jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId()); }); } 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 75c988f6154..77369aed164 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 @@ -88,7 +88,7 @@ class BasicErrorControllerIntegrationTests { void testErrorForMachineClientDefault() { load(); ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl("?trace=true"), Map.class); - assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", null, "", "/"); + assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", null, null, "/"); assertThat(entity.getBody()).doesNotContainKey("exception"); assertThat(entity.getBody()).doesNotContainKey("trace"); } @@ -148,7 +148,7 @@ class BasicErrorControllerIntegrationTests { @SuppressWarnings({ "rawtypes", "unchecked" }) private void exceptionWithoutStackTraceAndMessage(String path) { ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl(path), Map.class); - assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", IllegalStateException.class, "", "/"); + assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", IllegalStateException.class, null, "/"); assertThat(entity.getBody()).doesNotContainKey("trace"); } @@ -158,7 +158,7 @@ class BasicErrorControllerIntegrationTests { load("--server.error.include-exception=true"); ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl("/annotated"), Map.class); assertErrorAttributes(entity.getBody(), "400", "Bad Request", TestConfiguration.Errors.ExpectedException.class, - "", "/annotated"); + null, "/annotated"); } @Test @@ -176,7 +176,7 @@ class BasicErrorControllerIntegrationTests { load("--server.error.include-exception=true"); ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl("/annotatedNoReason"), Map.class); assertErrorAttributes(entity.getBody(), "406", "Not Acceptable", - TestConfiguration.Errors.NoReasonExpectedException.class, "", "/annotatedNoReason"); + TestConfiguration.Errors.NoReasonExpectedException.class, null, "/annotatedNoReason"); } @Test @@ -261,14 +261,14 @@ class BasicErrorControllerIntegrationTests { @SuppressWarnings({ "rawtypes", "unchecked" }) private void bindingExceptionWithErrors(String param) { ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class); - assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind"); + assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, null, "/bind"); assertThat(entity.getBody()).containsKey("errors"); } @SuppressWarnings({ "rawtypes", "unchecked" }) private void bindingExceptionWithoutErrors(String param) { ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class); - assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind"); + assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, null, "/bind"); assertThat(entity.getBody()).doesNotContainKey("errors"); } @@ -283,7 +283,7 @@ class BasicErrorControllerIntegrationTests { @SuppressWarnings({ "rawtypes", "unchecked" }) private void bindingExceptionWithoutMessage(String param) { ResponseEntity entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class); - assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind"); + assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, null, "/bind"); assertThat(entity.getBody()).doesNotContainKey("errors"); } @@ -294,7 +294,7 @@ class BasicErrorControllerIntegrationTests { RequestEntity request = RequestEntity.post(URI.create(createUrl("/bodyValidation"))) .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).body("{}"); ResponseEntity entity = new TestRestTemplate().exchange(request, Map.class); - assertErrorAttributes(entity.getBody(), "400", "Bad Request", MethodArgumentNotValidException.class, "", + assertErrorAttributes(entity.getBody(), "400", "Bad Request", MethodArgumentNotValidException.class, null, "/bodyValidation"); assertThat(entity.getBody()).doesNotContainKey("errors"); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java index c96b4376e5a..095ab007924 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java @@ -73,7 +73,7 @@ public class DefaultErrorAttributes implements ErrorAttributes { errorAttributes.remove("trace"); } if (!options.isIncluded(Include.MESSAGE) && errorAttributes.get("message") != null) { - errorAttributes.put("message", ""); + errorAttributes.remove("message"); } if (!options.isIncluded(Include.BINDING_ERRORS)) { errorAttributes.remove("errors"); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributes.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributes.java index a14f599af31..248f6ffeae7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributes.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributes.java @@ -96,7 +96,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException errorAttributes.remove("trace"); } if (!options.isIncluded(Include.MESSAGE) && errorAttributes.get("message") != null) { - errorAttributes.put("message", ""); + errorAttributes.remove("message"); } if (!options.isIncluded(Include.BINDING_ERRORS)) { errorAttributes.remove("errors"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java index 7fbba7b3b5e..db5e3c9434d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java @@ -93,7 +93,7 @@ class DefaultErrorAttributesTests { Map attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, error), ErrorAttributeOptions.defaults()); assertThat(attributes.get("error")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.getReasonPhrase()); - assertThat(attributes.get("message")).isEqualTo(""); + assertThat(attributes).doesNotContainKey("message"); assertThat(attributes.get("status")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.value()); } @@ -148,7 +148,7 @@ class DefaultErrorAttributesTests { Map attributes = this.errorAttributes.getErrorAttributes(serverRequest, ErrorAttributeOptions.defaults()); assertThat(this.errorAttributes.getError(serverRequest)).isSameAs(error); - assertThat(attributes.get("message")).isEqualTo(""); + assertThat(attributes).doesNotContainKey("message"); } @Test @@ -256,7 +256,7 @@ class DefaultErrorAttributesTests { MockServerHttpRequest request = MockServerHttpRequest.get("/test").build(); Map attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, ex), ErrorAttributeOptions.defaults()); - assertThat(attributes).containsEntry("message", ""); + assertThat(attributes).doesNotContainKey("message"); assertThat(attributes).doesNotContainKey("errors"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributesTests.java index 491ade7d78f..9b1bf5e58dd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributesTests.java @@ -113,7 +113,7 @@ class DefaultErrorAttributesTests { ErrorAttributeOptions.defaults()); assertThat(this.errorAttributes.getError(this.webRequest)).isSameAs(ex); assertThat(attributes).doesNotContainKey("exception"); - assertThat(attributes.get("message").toString()).contains(""); + assertThat(attributes).doesNotContainKey("message"); } @Test @@ -131,7 +131,7 @@ class DefaultErrorAttributesTests { Map attributes = this.errorAttributes.getErrorAttributes(this.webRequest, ErrorAttributeOptions.defaults()); assertThat(attributes).doesNotContainKey("exception"); - assertThat(attributes.get("message")).asString().contains(""); + assertThat(attributes).doesNotContainKey("message"); } @Test @@ -210,7 +210,7 @@ class DefaultErrorAttributesTests { .isEqualTo("Validation failed for object='objectName'. Error count: 1"); } else { - assertThat(attributes.get("message")).isEqualTo(""); + assertThat(attributes).doesNotContainKey("message"); } if (options.isIncluded(Include.BINDING_ERRORS)) { assertThat(attributes.get("errors")).isEqualTo(bindingResult.getAllErrors());