Allow null from RestClient exchange methods

Closes gh-33779
This commit is contained in:
rstoyanchev 2024-10-23 19:08:54 +01:00
parent 4a81f2c904
commit bbe362c0e6
2 changed files with 8 additions and 1 deletions

View File

@ -455,14 +455,18 @@ final class DefaultRestClient implements RestClient {
@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");

View File

@ -561,6 +561,7 @@ public interface RestClient {
* @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);
}
@ -592,6 +593,7 @@ public interface RestClient {
* @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);
@ -609,6 +611,7 @@ public interface RestClient {
* @return the exchanged type
* @throws IOException in case of I/O errors
*/
@Nullable
T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException;
}