Skip to content

Clarify whether HttpInputMessage.getBody() is allowed to return null [SPR-13563] #18139

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
spring-projects-issues opened this issue Oct 12, 2015 · 1 comment
Assignees
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Juergen Hoeller opened SPR-13563 and commented

Initiated by #886, we should clarify whether HttpInputMessage.getBody() is allowed to return null, in particular for ClientHttpResponse implementations. BufferingClientHttpResponseWrapper should then defensively check for a null body before trying to buffer it into a byte array, or we should enforce non-null body values where they can currently be null: specifically, in HttpComponents(Async)ClientHttpResponse which seems to be the only implementation that currently returns null for an empty body to begin with.


Affects: 3.2.14, 4.1.7, 4.2.1

Referenced from: commits a5f81a0, ca60d79, 8a82259, 66177df

Backported to: 4.1.8, 3.2.15

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

According to today's analysis, getBody() was never meant to return null. I've explicitly clarified this on HttpInputMessage as well as HttpOutputMessage, and consequently fixed HttpComponents(Async)ClientHttpResponse to return an empty stream instead of null.

This makes the existing BufferingClientHttpResponseWrapper work without any code changes, never running into an IllegalArgumentException out of StreamUtils now.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.2 milestone Jan 11, 2019
This was referenced Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants