mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Lazily initialize ProblemDetail for picking up actual status code
Closes gh-35829
(cherry picked from commit 3026f0a49b)
This commit is contained in:
+9
-5
@@ -25,8 +25,8 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.ErrorResponse;
|
||||
|
||||
/**
|
||||
* Fatal binding exception, thrown when we want to
|
||||
* treat binding exceptions as unrecoverable.
|
||||
* Fatal binding exception, thrown when we want to treat binding exceptions
|
||||
* as unrecoverable.
|
||||
*
|
||||
* <p>Extends ServletException for convenient throwing in any Servlet resource
|
||||
* (such as a Filter), and NestedServletException for proper root cause handling
|
||||
@@ -38,13 +38,14 @@ import org.springframework.web.ErrorResponse;
|
||||
@SuppressWarnings("serial")
|
||||
public class ServletRequestBindingException extends ServletException implements ErrorResponse {
|
||||
|
||||
private final ProblemDetail body = ProblemDetail.forStatus(getStatusCode());
|
||||
|
||||
private final String messageDetailCode;
|
||||
|
||||
@Nullable
|
||||
private final Object[] messageDetailArguments;
|
||||
|
||||
@Nullable
|
||||
private ProblemDetail body;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with a message only.
|
||||
@@ -108,7 +109,10 @@ public class ServletRequestBindingException extends ServletException implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProblemDetail getBody() {
|
||||
public synchronized ProblemDetail getBody() {
|
||||
if (this.body == null) {
|
||||
this.body = ProblemDetail.forStatus(getStatusCode());
|
||||
}
|
||||
return this.body;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user