Skip to content

Commit 84bd44e

Browse files
committed
Use nullable body consistently in HttpClientErrorException
Closes gh-35482
1 parent 2faed3c commit 84bd44e

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Exception thrown when an HTTP 4xx is received.
2929
*
3030
* @author Arjen Poutsma
31+
* @author Sebastien Deleuze
3132
* @since 3.0
3233
* @see DefaultResponseErrorHandler
3334
*/
@@ -85,7 +86,7 @@ public HttpClientErrorException(String message, HttpStatusCode statusCode, Strin
8586
* @since 5.1
8687
*/
8788
public static HttpClientErrorException create(
88-
HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
89+
HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
8990

9091
return create(null, statusCode, statusText, headers, body, charset);
9192
}
@@ -97,7 +98,7 @@ public static HttpClientErrorException create(
9798
*/
9899
@SuppressWarnings("deprecation")
99100
public static HttpClientErrorException create(@Nullable String message, HttpStatusCode statusCode,
100-
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
101+
String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
101102

102103
if (statusCode instanceof HttpStatus status) {
103104
return switch (status) {
@@ -160,12 +161,12 @@ public static HttpClientErrorException create(@Nullable String message, HttpStat
160161
@SuppressWarnings("serial")
161162
public static final class BadRequest extends HttpClientErrorException {
162163

163-
private BadRequest(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
164+
private BadRequest(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
164165
super(HttpStatus.BAD_REQUEST, statusText, headers, body, charset);
165166
}
166167

167168
private BadRequest(String message, String statusText,
168-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
169+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
169170

170171
super(message, HttpStatus.BAD_REQUEST, statusText, headers, body, charset);
171172
}
@@ -178,12 +179,12 @@ private BadRequest(String message, String statusText,
178179
@SuppressWarnings("serial")
179180
public static final class Unauthorized extends HttpClientErrorException {
180181

181-
private Unauthorized(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
182+
private Unauthorized(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
182183
super(HttpStatus.UNAUTHORIZED, statusText, headers, body, charset);
183184
}
184185

185186
private Unauthorized(String message, String statusText,
186-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
187+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
187188

188189
super(message, HttpStatus.UNAUTHORIZED, statusText, headers, body, charset);
189190
}
@@ -196,12 +197,12 @@ private Unauthorized(String message, String statusText,
196197
@SuppressWarnings("serial")
197198
public static final class Forbidden extends HttpClientErrorException {
198199

199-
private Forbidden(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
200+
private Forbidden(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
200201
super(HttpStatus.FORBIDDEN, statusText, headers, body, charset);
201202
}
202203

203204
private Forbidden(String message, String statusText,
204-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
205+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
205206

206207
super(message, HttpStatus.FORBIDDEN, statusText, headers, body, charset);
207208
}
@@ -214,12 +215,12 @@ private Forbidden(String message, String statusText,
214215
@SuppressWarnings("serial")
215216
public static final class NotFound extends HttpClientErrorException {
216217

217-
private NotFound(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
218+
private NotFound(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
218219
super(HttpStatus.NOT_FOUND, statusText, headers, body, charset);
219220
}
220221

221222
private NotFound(String message, String statusText,
222-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
223+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
223224

224225
super(message, HttpStatus.NOT_FOUND, statusText, headers, body, charset);
225226
}
@@ -232,12 +233,12 @@ private NotFound(String message, String statusText,
232233
@SuppressWarnings("serial")
233234
public static final class MethodNotAllowed extends HttpClientErrorException {
234235

235-
private MethodNotAllowed(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
236+
private MethodNotAllowed(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
236237
super(HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset);
237238
}
238239

239240
private MethodNotAllowed(String message, String statusText,
240-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
241+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
241242

242243
super(message, HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset);
243244
}
@@ -250,12 +251,12 @@ private MethodNotAllowed(String message, String statusText,
250251
@SuppressWarnings("serial")
251252
public static final class NotAcceptable extends HttpClientErrorException {
252253

253-
private NotAcceptable(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
254+
private NotAcceptable(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
254255
super(HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset);
255256
}
256257

257258
private NotAcceptable(String message, String statusText,
258-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
259+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
259260

260261
super(message, HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset);
261262
}
@@ -268,11 +269,11 @@ private NotAcceptable(String message, String statusText,
268269
@SuppressWarnings("serial")
269270
public static final class Conflict extends HttpClientErrorException {
270271

271-
private Conflict(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
272+
private Conflict(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
272273
super(HttpStatus.CONFLICT, statusText, headers, body, charset);
273274
}
274275

275-
private Conflict(String message, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
276+
private Conflict(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
276277
super(message, HttpStatus.CONFLICT, statusText, headers, body, charset);
277278
}
278279
}
@@ -284,11 +285,11 @@ private Conflict(String message, String statusText, HttpHeaders headers, byte[]
284285
@SuppressWarnings("serial")
285286
public static final class Gone extends HttpClientErrorException {
286287

287-
private Gone(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
288+
private Gone(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
288289
super(HttpStatus.GONE, statusText, headers, body, charset);
289290
}
290291

291-
private Gone(String message, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
292+
private Gone(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
292293
super(message, HttpStatus.GONE, statusText, headers, body, charset);
293294
}
294295
}
@@ -300,12 +301,12 @@ private Gone(String message, String statusText, HttpHeaders headers, byte[] body
300301
@SuppressWarnings("serial")
301302
public static final class UnsupportedMediaType extends HttpClientErrorException {
302303

303-
private UnsupportedMediaType(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
304+
private UnsupportedMediaType(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
304305
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset);
305306
}
306307

307308
private UnsupportedMediaType(String message, String statusText,
308-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
309+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
309310

310311
super(message, HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset);
311312
}
@@ -318,12 +319,12 @@ private UnsupportedMediaType(String message, String statusText,
318319
@SuppressWarnings("serial")
319320
public static final class UnprocessableContent extends HttpClientErrorException {
320321

321-
private UnprocessableContent(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
322+
private UnprocessableContent(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
322323
super(HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset);
323324
}
324325

325326
private UnprocessableContent(String message, String statusText,
326-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
327+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
327328

328329
super(message, HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset);
329330
}
@@ -338,12 +339,12 @@ private UnprocessableContent(String message, String statusText,
338339
@SuppressWarnings("serial")
339340
public static final class UnprocessableEntity extends HttpClientErrorException {
340341

341-
private UnprocessableEntity(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
342+
private UnprocessableEntity(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
342343
super(HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset);
343344
}
344345

345346
private UnprocessableEntity(String message, String statusText,
346-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
347+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
347348

348349
super(message, HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset);
349350
}
@@ -356,12 +357,12 @@ private UnprocessableEntity(String message, String statusText,
356357
@SuppressWarnings("serial")
357358
public static final class TooManyRequests extends HttpClientErrorException {
358359

359-
private TooManyRequests(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
360+
private TooManyRequests(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
360361
super(HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset);
361362
}
362363

363364
private TooManyRequests(String message, String statusText,
364-
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
365+
HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) {
365366

366367
super(message, HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset);
367368
}

0 commit comments

Comments
 (0)