Skip to content

Improve Javadoc of RestOperations#exchange for responses without a body #26599

Closed
@metacubed

Description

@metacubed

Affects: spring-web:5.3.4


The various RestTemplate.exchange() methods do not mark the parameter Class<T> responseType as @Nullable. For example:
https://github.com/spring-projects/spring-framework/blob/v5.3.4/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java#L597

public <T> ResponseEntity<T> exchange(String url, HttpMethod method,
    @Nullable HttpEntity<?> requestEntity, /* >HERE< */ Class<T> responseType, Object... uriVariables)
    throws RestClientException {

        RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
        ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
        return nonNull(execute(url, method, requestCallback, responseExtractor, uriVariables));
}

This causes code analysis warnings for methods which do not return a response, such as DELETE, forcing developers to use Void.TYPE as the responseType instead of null.


The usages of that parameter explicitly expect null values as valid cases. For example:

In the HttpEntityRequestCallback class,

public HttpEntityRequestCallback(@Nullable Object requestBody, @Nullable Type responseType) {
    // ...
}

In the ResponseEntityResponseExtractor class,

public ResponseEntityResponseExtractor(@Nullable Type responseType) {
    if (responseType != null && Void.class != responseType) {
        this.delegate = new HttpMessageConverterExtractor<>(responseType, getMessageConverters(), logger);
    }
    else {
        this.delegate = null;
    }
}

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions