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

Java Runtime Finalizer closes all COSDocument-Objects no mater if they are still being used or not

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Bug
    • Affects Version/s: 2.0.20, 2.0.21
    • Fix Version/s: None
    • Component/s: Writing
    • Labels:
      None
    • Environment:
      SpringBoot, JDK1.8

      Description

      I am running a spring boot based microservice that creates pdf's for a mimaki digital printer.

      Every pdf contains multiple type labels with an individual datamatrix code on it, which I have been creating with PDFbox.

      A single run for a job takes about 3-4 minutes. The service is running flawlessly for hours but sometimes during a large job the following Exception is thrown while writing the resulting pdf to disc.

      Caused by: java.io.IOException: COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?
      at org.apache.pdfbox.cos.COSStream.checkClosed(COSStream.java:83)
      at org.apache.pdfbox.cos.COSStream.createRawInputStream(COSStream.java:133)
      at org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1217)
      at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:404)
      at org.apache.pdfbox.cos.COSObject.accept(COSObject.java:158)
      at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:524)
      at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObjects(COSWriter.java:462)
      at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:446)
      at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1111)
      at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:449)
      at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1384)
      at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1271)
      at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1350)
      at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1321)
      at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1309)
      at de.dehn.middleware.service.PDFService$PDFCreatorCallable.save(PDFService.java:458)

      I have tracked it down and found out that the Java Finalizer calls the finalize() Method on all COSDocument Objects and closes them forcefully no matter I've they are still being used or not.

       

       

       

       

        Attachments

        1. screenshot-1.png
          70 kB
          Gilbert

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Hofstaetter Gilbert
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: