Browse Source

Allow null from RestClient exchange methods

Closes gh-33779
pull/33850/head
rstoyanchev 1 year ago
parent
commit
bbe362c0e6
  1. 6
      spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java
  2. 3
      spring-web/src/main/java/org/springframework/web/client/RestClient.java

6
spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java

@ -455,14 +455,18 @@ final class DefaultRestClient implements RestClient {
@Override @Override
public ResponseSpec retrieve() { public ResponseSpec retrieve() {
return exchangeInternal(DefaultResponseSpec::new, false); ResponseSpec responseSpec = exchangeInternal(DefaultResponseSpec::new, false);
Assert.state(responseSpec != null, "No ResponseSpec");
return responseSpec;
} }
@Override @Override
@Nullable
public <T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close) { public <T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close) {
return exchangeInternal(exchangeFunction, close); return exchangeInternal(exchangeFunction, close);
} }
@Nullable
private <T> T exchangeInternal(ExchangeFunction<T> exchangeFunction, boolean close) { private <T> T exchangeInternal(ExchangeFunction<T> exchangeFunction, boolean close) {
Assert.notNull(exchangeFunction, "ExchangeFunction must not be null"); Assert.notNull(exchangeFunction, "ExchangeFunction must not be null");

3
spring-web/src/main/java/org/springframework/web/client/RestClient.java

@ -561,6 +561,7 @@ public interface RestClient {
* @param <T> the type the response will be transformed to * @param <T> the type the response will be transformed to
* @return the value returned from the exchange function * @return the value returned from the exchange function
*/ */
@Nullable
default <T> T exchange(ExchangeFunction<T> exchangeFunction) { default <T> T exchange(ExchangeFunction<T> exchangeFunction) {
return exchange(exchangeFunction, true); return exchange(exchangeFunction, true);
} }
@ -592,6 +593,7 @@ public interface RestClient {
* @param <T> the type the response will be transformed to * @param <T> the type the response will be transformed to
* @return the value returned from the exchange function * @return the value returned from the exchange function
*/ */
@Nullable
<T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close); <T> T exchange(ExchangeFunction<T> exchangeFunction, boolean close);
@ -609,6 +611,7 @@ public interface RestClient {
* @return the exchanged type * @return the exchanged type
* @throws IOException in case of I/O errors * @throws IOException in case of I/O errors
*/ */
@Nullable
T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException; T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException;
} }

Loading…
Cancel
Save