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

ObjectInputStream does not reliably close the underlying stream

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      I just spent hours to find out that the official ObjectInputStream Java class shows some pretty bad behavior if the input stream is corrupted. In expression: ObjectInputStream .close() won't close the underlying stream after trying ObjectInputStream .readObject() on an input stream with a bad header. So

      try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(...))) {
          ois.readObject();
          ...
      }

      does NOT (!) reliably close the file handle! The safe way to go is to use try-with-resources directly on the file input stream

      try(InputStream is = new FileInputStream(...)) {
          ObjectInputStream ois = new ObjectInputStream(is);
          ois.readObject();
          ...
      }

      and never on ObjectInputStream directly. Java is a very nice language in general, but this implementation does not live up to it. Please fix that and make it behave like everyone would expect.


      REPRODUCIBILITY :
      This bug can be reproduced always.

          Loading...
          Uploaded image for project: 'JDK'
          1. JDK
          2. JDK-8147534

          ObjectInputStream does not reliably close the underlying stream

              FULL PRODUCT VERSION :
              java version "1.8.0_66"
              Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
              Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

              ADDITIONAL OS VERSION INFORMATION :
              Microsoft Windows [Version 6.1.7601]

              A DESCRIPTION OF THE PROBLEM :
              I just spent hours to find out that the official ObjectInputStream Java class shows some pretty bad behavior if the input stream is corrupted. In expression: ObjectInputStream .close() won't close the underlying stream after trying ObjectInputStream .readObject() on an input stream with a bad header. So

              try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(...))) {
                  ois.readObject();
                  ...
              }

              does NOT (!) reliably close the file handle! The safe way to go is to use try-with-resources directly on the file input stream

              try(InputStream is = new FileInputStream(...)) {
                  ObjectInputStream ois = new ObjectInputStream(is);
                  ois.readObject();
                  ...
              }

              and never on ObjectInputStream directly. Java is a very nice language in general, but this implementation does not live up to it. Please fix that and make it behave like everyone would expect.


              REPRODUCIBILITY :
              This bug can be reproduced always.

                    smarks Stuart Marks
                    webbuggrp Webbug Group
                    Votes:
                    0 Vote for this issue
                    Watchers:
                    4 Start watching this issue

                      Created:
                      Updated:
                      Resolved:

                        smarks Stuart Marks
                        webbuggrp Webbug Group
                        Votes:
                        0 Vote for this issue
                        Watchers:
                        4 Start watching this issue

                          Created:
                          Updated:
                          Resolved: