Skip to content

Commit c2ec46c

Browse files
Polish "Fix include exception handling in DefaultErrorAttributes"
See gh-22750
1 parent c49605c commit c2ec46c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ void includeException() {
164164
assertThat(attributes.get("message")).isEqualTo("Test");
165165
}
166166

167+
@Test
168+
@SuppressWarnings("deprecation")
169+
void excludeExceptionWithDeprecatedConstructor() {
170+
RuntimeException error = new RuntimeException("Test");
171+
this.errorAttributes = new DefaultErrorAttributes(false);
172+
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
173+
ServerRequest serverRequest = buildServerRequest(request, error);
174+
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(serverRequest,
175+
ErrorAttributeOptions.of());
176+
assertThat(this.errorAttributes.getError(serverRequest)).isSameAs(error);
177+
assertThat(attributes.get("exception")).isNull();
178+
}
179+
167180
@Test
168181
void processResponseStatusException() {
169182
RuntimeException nested = new RuntimeException("Test");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributesTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ void withExceptionAttribute() {
231231
assertThat(attributes.get("message")).isEqualTo("Test");
232232
}
233233

234+
@Test
235+
@SuppressWarnings("deprecation")
236+
void excludeExceptionAttributeWithDeprecatedConstructor() {
237+
DefaultErrorAttributes errorAttributes = new DefaultErrorAttributes(false);
238+
RuntimeException ex = new RuntimeException("Test");
239+
this.request.setAttribute("javax.servlet.error.exception", ex);
240+
Map<String, Object> attributes = errorAttributes.getErrorAttributes(this.webRequest,
241+
ErrorAttributeOptions.of());
242+
assertThat(attributes.get("exception")).isNull();
243+
}
244+
234245
@Test
235246
void withStackTraceAttribute() {
236247
RuntimeException ex = new RuntimeException("Test");

0 commit comments

Comments
 (0)