Skip to content

Commit bbe362c

Browse files
committed
Allow null from RestClient exchange methods
Closes gh-33779
1 parent 4a81f2c commit bbe362c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,18 @@ private void logBody(Object body, @Nullable MediaType mediaType, HttpMessageConv
455455

456456
@Override
457457
public ResponseSpec retrieve() {
458-
return exchangeInternal(DefaultResponseSpec::new, false);
458+
ResponseSpec responseSpec = exchangeInternal(DefaultResponseSpec::new, false);
459+
Assert.state(responseSpec != null, "No ResponseSpec");
460+
return responseSpec;
459461
}
460462

461463
@Override
464+
@Nullable
462465
public <T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close) {
463466
return exchangeInternal(exchangeFunction, close);
464467
}
465468

469+
@Nullable
466470
private <T> T exchangeInternal(ExchangeFunction<T> exchangeFunction, boolean close) {
467471
Assert.notNull(exchangeFunction, "ExchangeFunction must not be null");
468472

Diff for: spring-web/src/main/java/org/springframework/web/client/RestClient.java

+3
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ interface RequestHeadersSpec<S extends RequestHeadersSpec<S>> {
561561
* @param <T> the type the response will be transformed to
562562
* @return the value returned from the exchange function
563563
*/
564+
@Nullable
564565
default <T> T exchange(ExchangeFunction<T> exchangeFunction) {
565566
return exchange(exchangeFunction, true);
566567
}
@@ -592,6 +593,7 @@ default <T> T exchange(ExchangeFunction<T> exchangeFunction) {
592593
* @param <T> the type the response will be transformed to
593594
* @return the value returned from the exchange function
594595
*/
596+
@Nullable
595597
<T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close);
596598

597599

@@ -609,6 +611,7 @@ interface ExchangeFunction<T> {
609611
* @return the exchanged type
610612
* @throws IOException in case of I/O errors
611613
*/
614+
@Nullable
612615
T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException;
613616
}
614617

0 commit comments

Comments
 (0)