From 84bd44e5de11702d9f9e97b497ce40c8eb26bbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 15 Sep 2025 10:18:04 +0200 Subject: [PATCH] Use nullable body consistently in HttpClientErrorException Closes gh-35482 --- .../web/client/HttpClientErrorException.java | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java index d2add587043..ce6bf490db6 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java @@ -28,6 +28,7 @@ import org.springframework.http.HttpStatusCode; * Exception thrown when an HTTP 4xx is received. * * @author Arjen Poutsma + * @author Sebastien Deleuze * @since 3.0 * @see DefaultResponseErrorHandler */ @@ -85,7 +86,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { * @since 5.1 */ public static HttpClientErrorException create( - HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { return create(null, statusCode, statusText, headers, body, charset); } @@ -97,7 +98,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { */ @SuppressWarnings("deprecation") public static HttpClientErrorException create(@Nullable String message, HttpStatusCode statusCode, - String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { if (statusCode instanceof HttpStatus status) { return switch (status) { @@ -160,12 +161,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class BadRequest extends HttpClientErrorException { - private BadRequest(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private BadRequest(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.BAD_REQUEST, statusText, headers, body, charset); } private BadRequest(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.BAD_REQUEST, statusText, headers, body, charset); } @@ -178,12 +179,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Unauthorized extends HttpClientErrorException { - private Unauthorized(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private Unauthorized(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.UNAUTHORIZED, statusText, headers, body, charset); } private Unauthorized(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.UNAUTHORIZED, statusText, headers, body, charset); } @@ -196,12 +197,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Forbidden extends HttpClientErrorException { - private Forbidden(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private Forbidden(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.FORBIDDEN, statusText, headers, body, charset); } private Forbidden(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.FORBIDDEN, statusText, headers, body, charset); } @@ -214,12 +215,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class NotFound extends HttpClientErrorException { - private NotFound(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private NotFound(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.NOT_FOUND, statusText, headers, body, charset); } private NotFound(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.NOT_FOUND, statusText, headers, body, charset); } @@ -232,12 +233,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class MethodNotAllowed extends HttpClientErrorException { - private MethodNotAllowed(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private MethodNotAllowed(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset); } private MethodNotAllowed(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset); } @@ -250,12 +251,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class NotAcceptable extends HttpClientErrorException { - private NotAcceptable(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private NotAcceptable(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset); } private NotAcceptable(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset); } @@ -268,11 +269,11 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Conflict extends HttpClientErrorException { - private Conflict(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private Conflict(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.CONFLICT, statusText, headers, body, charset); } - private Conflict(String message, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private Conflict(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.CONFLICT, statusText, headers, body, charset); } } @@ -284,11 +285,11 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Gone extends HttpClientErrorException { - private Gone(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private Gone(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.GONE, statusText, headers, body, charset); } - private Gone(String message, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private Gone(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.GONE, statusText, headers, body, charset); } } @@ -300,12 +301,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class UnsupportedMediaType extends HttpClientErrorException { - private UnsupportedMediaType(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private UnsupportedMediaType(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset); } private UnsupportedMediaType(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset); } @@ -318,12 +319,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class UnprocessableContent extends HttpClientErrorException { - private UnprocessableContent(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private UnprocessableContent(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset); } private UnprocessableContent(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset); } @@ -338,12 +339,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class UnprocessableEntity extends HttpClientErrorException { - private UnprocessableEntity(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private UnprocessableEntity(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset); } private UnprocessableEntity(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset); } @@ -356,12 +357,12 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class TooManyRequests extends HttpClientErrorException { - private TooManyRequests(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + private TooManyRequests(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset); } private TooManyRequests(String message, String statusText, - HttpHeaders headers, byte[] body, @Nullable Charset charset) { + HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset); }