Skip to content

JdkClientHttpRequestFactory not compatible with BufferingClientHttpRequestFactory in 6.1 M3 #31027

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
alexcrownus opened this issue Aug 10, 2023 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)

Comments

@alexcrownus
Copy link

In Spring Framework 6.1 M3, using BufferingClientHttpRequestFactory with JdkClientHttpRequestFactory throws an exception

java.lang.IllegalArgumentException: non-positive contentLength: 0.

The issue seems to be from class BufferingClientHttpResponseWrapper, method

    @Override
    public InputStream getBody() throws IOException {
        if (this.body == null) {
            this.body = StreamUtils.copyToByteArray(this.response.getBody()) 
        }
        return new ByteArrayInputStream(this.body);
    }

Since BufferingClientHttpResponseWrapper is not public, I copied the class and was able to fix the issue with

    @Override
    public InputStream getBody() throws IOException {
        if (this.body == null) {
            this.body = StreamUtils.copyToByteArray((this.response.getBody() != null) ? this.response.getBody() : new ByteArrayInputStream(new byte[0]));
        }
        return new ByteArrayInputStream(this.body);
    }

Not sure if this is a good fix but it works.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 10, 2023
@sbrannen sbrannen changed the title JdkClientHttpRequestFactory not compatible with BufferingClientHttpRequestFactory - 6.1 M3 JdkClientHttpRequestFactory not compatible with BufferingClientHttpRequestFactory in 6.1 M3 Aug 14, 2023
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Aug 14, 2023
@sbrannen
Copy link
Member

sbrannen commented Aug 14, 2023

The contract of org.springframework.http.HttpInputMessage.getBody() states that it can never return null.

So, in theory, this.response.getBody() should never be null.

Can you provide a minimal example that demonstrates the behavior you've described?

Also, a complete stack trace would be helpful.

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Aug 14, 2023
@poutsma poutsma self-assigned this Aug 16, 2023
@poutsma
Copy link
Contributor

poutsma commented Aug 16, 2023

Indeed, like @sbrannen said, HttpInputMesage::getBody should not return null. And looking at the JdkClientHttpResponse class, you can see that we specifically guard against a null body stream:

this.body = (inputStream != null ? inputStream : InputStream.nullInputStream());

@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Aug 21, 2023
@spring-projects-issues
Copy link
Collaborator

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2023
@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 28, 2023
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)
Projects
None yet
Development

No branches or pull requests

4 participants