Skip to content

Commit

Permalink
Allow null from RestClient exchange methods
Browse files Browse the repository at this point in the history
Closes gh-33779
  • Loading branch information
rstoyanchev committed Oct 23, 2024
1 parent 4a81f2c commit bbe362c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,18 @@ private void logBody(Object body, @Nullable MediaType mediaType, HttpMessageConv

@Override
public ResponseSpec retrieve() {
return exchangeInternal(DefaultResponseSpec::new, false);
ResponseSpec responseSpec = exchangeInternal(DefaultResponseSpec::new, false);
Assert.state(responseSpec != null, "No ResponseSpec");
return responseSpec;
}

@Override
@Nullable
public <T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close) {
return exchangeInternal(exchangeFunction, close);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ interface RequestHeadersSpec<S extends RequestHeadersSpec<S>> {
* @param <T> the type the response will be transformed to
* @return the value returned from the exchange function
*/
@Nullable
default <T> T exchange(ExchangeFunction<T> exchangeFunction) {
return exchange(exchangeFunction, true);
}
Expand Down Expand Up @@ -592,6 +593,7 @@ default <T> T exchange(ExchangeFunction<T> exchangeFunction) {
* @param <T> the type the response will be transformed to
* @return the value returned from the exchange function
*/
@Nullable
<T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close);


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

Expand Down

0 comments on commit bbe362c

Please sign in to comment.