Skip to content

NPE in SimpleClient-HttpURLConnection with errorstream-buffering [SPR-16773] #21313

@spring-projects-issues

Description

@spring-projects-issues

Markus opened SPR-16773 and commented

For an Jersey-Client we enabled errorstream-buffering in HttpUrlConnection. Due to global properties this also affected Spring-SimpleClientHttpRequestFactory and subsequently caused NullPointerException for httpstatus-errors. Seems to happen everytime for 4XX or 5XX with non-empty body.

It seems that Java8-HttpUrlConnection doesnt expect when buffered errorstream is attempted to drain after already closed. The drain-after-close occurs because DefaultResponseErrorHandler reads and closes the response-inputstream, and a later finally-block in RestTemplate#doExecute drains+closes again.

 

java.lang.NullPointerException
 at sun.net.www.protocol.http.HttpURLConnection$ErrorStream.read(HttpURLConnection.java:3690)
 at sun.net.www.protocol.http.HttpURLConnection$ErrorStream.read(HttpURLConnection.java:3685)
 at org.springframework.util.StreamUtils.drain(StreamUtils.java:201)
 at org.springframework.http.client.SimpleClientHttpResponse.close(SimpleClientHttpResponse.java:103)
 at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:747)
 at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:686)
 

 

I will put up a MergeRequest shortly


Affects: 4.3.16, 5.0.5

Reference URL: #1810

Issue Links:

Backported to: 4.3.17

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions