From 3a37e18066f2edf999caa5d54d432c2fe47efff0 Mon Sep 17 00:00:00 2001 From: Baljit Singh Date: Tue, 29 Nov 2022 08:32:24 -0500 Subject: [PATCH] ResponseStatusException sets detail from reason again, again - leftover item that was not fully resolved in a27f2e994b632a63ca1bbd6f3de5d9b60246ccaa --- .../web/server/MethodNotAllowedException.java | 4 +++- .../web/server/MissingRequestValueException.java | 1 - .../springframework/web/server/ResponseStatusException.java | 1 + .../annotation/ResponseStatusExceptionResolverTests.java | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java b/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java index 541171d29391..ab1d0aae0c81 100644 --- a/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java +++ b/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java @@ -56,7 +56,9 @@ public MethodNotAllowedException(String method, @Nullable Collection } this.method = method; this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods)); - setDetail(this.httpMethods.isEmpty() ? getReason() : "Supported methods: " + this.httpMethods); + if (!this.httpMethods.isEmpty()) { + setDetail("Supported methods: " + this.httpMethods); + } } diff --git a/spring-web/src/main/java/org/springframework/web/server/MissingRequestValueException.java b/spring-web/src/main/java/org/springframework/web/server/MissingRequestValueException.java index de439da0d373..281676507a71 100644 --- a/spring-web/src/main/java/org/springframework/web/server/MissingRequestValueException.java +++ b/spring-web/src/main/java/org/springframework/web/server/MissingRequestValueException.java @@ -42,7 +42,6 @@ public MissingRequestValueException(String name, Class type, String label, Me this.name = name; this.type = type; this.label = label; - setDetail(getReason()); } diff --git a/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java b/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java index 544c40a4dc22..dfbbbb3326e8 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java +++ b/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java @@ -78,6 +78,7 @@ public ResponseStatusException(int rawStatusCode, @Nullable String reason, @Null public ResponseStatusException(HttpStatusCode status, @Nullable String reason, @Nullable Throwable cause) { super(status, cause); this.reason = reason; + setDetail(reason); } /** diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java index eee6f72b9a70..677e2ab28416 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java @@ -111,7 +111,7 @@ public void notAnnotated() { } @Test // SPR-12903 - public void nestedException() throws Exception { + public void nestedException() { Exception cause = new StatusCodeAndReasonMessageException(); TypeMismatchException ex = new TypeMismatchException("value", ITestBean.class, cause); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); @@ -119,14 +119,14 @@ public void nestedException() throws Exception { } @Test - public void responseStatusException() throws Exception { + public void responseStatusException() { ResponseStatusException ex = new ResponseStatusException(HttpStatus.BAD_REQUEST); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertResolved(mav, 400, null); } @Test // SPR-15524 - public void responseStatusExceptionWithReason() throws Exception { + public void responseStatusExceptionWithReason() { ResponseStatusException ex = new ResponseStatusException(HttpStatus.BAD_REQUEST, "The reason"); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertResolved(mav, 400, "The reason");