Skip to content

RestClient exchange methods are not nullable #33779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rstoyanchev opened this issue Oct 23, 2024 · 4 comments
Closed

RestClient exchange methods are not nullable #33779

rstoyanchev opened this issue Oct 23, 2024 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@rstoyanchev
Copy link
Contributor

The retrieve workflow, a shortcut for exchange, can end with null, but exchange itself is not declared as Nullable. There is no reason why an response cannot be exchanged for a null value.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug labels Oct 23, 2024
@rstoyanchev rstoyanchev added this to the 6.1.15 milestone Oct 23, 2024
@rstoyanchev rstoyanchev self-assigned this Oct 23, 2024
@rstoyanchev rstoyanchev changed the title Rest client exchange methods are not nullable RestClient exchange methods are not nullable Oct 23, 2024
@Donghh0221
Copy link
Contributor

Donghh0221 commented Mar 28, 2025

@rstoyanchev Hi, I have some question abount this patch.

Currently, in a Kotlin environment, whenever we use the exchange method of RestClient, we have to perform a null check on the result due to the addition of @Nullable to its method signature.

Could you please share whether it is absolutely necessary to mark this method as @Nullable? Or, if there are alternative approaches to reduce the null-checking overhead in Kotlin, we would be grateful for your guidance. In most HTTP call scenarios, we expect the result to be non-null, and our team is experiencing an increase in unnecessary boilerplate code due to this change. We would also like to know if there are any plans or solutions being considered for future improvements.

In my opinion, it might be a good idea to add an additional non-nullable method in RestClientExtensions.kt.

@sdeleuze
Copy link
Contributor

@Donghh0221 I introduced a requiredExchange extension via #34692.

@Donghh0221
Copy link
Contributor

Donghh0221 commented Apr 4, 2025

@sdeleuze Thanks! It will helpful for kotlin user!

@sdeleuze
Copy link
Contributor

sdeleuze commented Apr 4, 2025

Notice we changed it to an exchangeForRequiredValue method useful for both Java and Kotlin developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants