Summary
The read method of HttpReponseInputStream
will throw an IOException if the thread is interrupted while blocking on HttpReponseInputStream::read
.
Problem
HttpResponseInputStream
catches InterruptedException
and ignores it. This makes it impossible to interrupt or cancel a thread that is downloading a file by copying the inputstream to disk.
Solution
If the thread is interrupted while blocking on HttpResponseInputStream::read
an IOException
will be thrown with the caught InterruptedException
set as the cause, and the thread interrupt status will be set. Also, the request will be cancelled and the InputStream
will be closed
Specification
java/net/http/HttpResponse.java:
an @implNote
is added to the API documentation of ResponseSubscribers::ofInputStream()
:
* @implNote The {@code read} method of the {@code InputStream}
* returned by the default implementation of this method will
* throw an {@code IOException} with the {@linkplain Thread#isInterrupted()
* thread interrupt status set} if the thread is interrupted
* while blocking on read. In that case, the request will also be
* cancelled and the {@code InputStream} will be closed.
- csr of
-
JDK-8294047 HttpResponseInputStream swallows interrupts
-
- Closed
-