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

Properties.loadFromXML fails with a chunked HTTP connection

XMLWordPrintable

    • b94
    • generic
    • generic
    • Verified

      If load a property object from a XML stream from a http request then it would fail with IOException: stream is closed.

      The cause is that ChunkedInputStream does not accept a read after a close. The problem occur only if there is a cache like with JNLP. With a cache it will detect with a read if there is EOF.

      The bug might be in HttpInputStream.close(). It should not call after a first close(). A possible fix can be to set the outputStream to null on a call of close.

              @Override

              public void close () throws IOException {
                  try {
                      if (outputStream != null) {
                          if (read() != -1) {
                              cacheRequest.abort();
                          } else {
                              outputStream.close();
                          }
                      }
                      super.close ();
                  } catch (IOException ioex) {
                      if (cacheRequest != null) {
                          cacheRequest.abort();
                      }
                      throw ioex;
                  } finally {
                      HttpURLConnection.this.http = null;
                      checkResponseCredentials (true);
                  }
              }
       

      This problem occur with all Java versions.

      java.io.IOException: stream is closed
        at sun.net.www.http.ChunkedInputStream.ensureOpen(Unknown Source)
        at sun.net.www.http.ChunkedInputStream.read(Unknown Source)
        at java.io.FilterInputStream.read(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(Unknown Source)
      at java.util.Properties.loadFromXML(Unknown Source)


      A workaround is to copy the stream in another stream.

        1. ChunkedEncodingTest.java
          5 kB
          Chris Hegarty
        2. PropsLoadFromChunked.java
          3 kB
          Chris Hegarty

            chegar Chris Hegarty
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: