JDK-6660405 : HttpURLConnection returns the wrong InputStream
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-02-07
  • Updated: 2013-09-19
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u71Fixed 7 b25Fixed
Related Reports
Duplicate :  
Relates :  
Description
When a CacheHandler is provided and the URL is found in the cache after a redirect, HttpURLConnection will return the wrong InputStream, i.e. the one from the redirect instead of the one from the Cache. Which will trigger an IOException since the InputStream from the redirect has been closed.
This is triggered on the second call to URLConnection.getInputStream().
One other way this happens is when checking headers first, like getResponseCode() then calling getInputStream().

Comments
EVALUATION This is due to keeping 2 separate InputStreams (one for networked connection, one for cached connection). One of them should be always be null, however after a redirect, the networked one is not set back to null, hence the conflict. Will fix as soon as possible.
08-02-2008