Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8298163

HttpResponseInputStream swallows interrupts

    XMLWordPrintable

Details

    • behavioral
    • low
    • InputStream::read is already specified to throw IOException. We're adding a new case where `IOException` might be thrown.
    • Java API
    • JDK

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              dclarke Darragh Clarke
              webbuggrp Webbug Group
              Daniel Fuchs
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: