Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4493

InputStream not closed after reading

    XMLWordPrintableJSON

Details

    Description

      Loading a PDF document like this:

       

      InputStream isPdfFile;
      PDDocument = PDDocument.load(isPdfFile);

       

      Within the load(...) method the following is called:

       

      public static PDDocument load(...){
      ...
      RandomAccessRead source = scratchFile.createBuffer(input);
      ...}

      Then in the Scratchfile:

       

      public RandomAccess createBuffer(InputStream input) throws IOException{
      ...
      while ((bytesRead = input.read(byteBuffer)) > -1)
      ...}

      Now the stream is consumed but it is not closed. This is a potential resource leak since it could not be reused anyway. The stream should be closed. (If you do not want to close an outside stream then at least a java doc comment in the PDDocument should hint that the stream must be closed afterwards...)

      Attachments

        Activity

          People

            tilman Tilman Hausherr
            tom_1st Lonzak
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: