[
https://issues.apache.org/jira/browse/PDFBOX-5013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17228266#comment-17228266
]
Michael Klink commented on PDFBOX-5013:
---------------------------------------
I think it's the other way around: As long as you use contents belonging to a
specific document, you have to hold a reference to its {{COSDocument}} (e.g.
via its {{PDDocument}}). By giving up all references to it and thereby making
it subject to garbage collection and finalization, you signal to PDFBox that
you don't need any of its contents anymore.
I assume you added pages (or annotations or arbitrary XObjects or or or) from
document A directly to document B without cloning them to their new document.
If you do that, you have to keep references to document A as long as you use
document B.
> Java Runtime Finalizer closes all COSDocument-Objects no mater if they are
> still being used or not
> --------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-5013
> URL: https://issues.apache.org/jira/browse/PDFBOX-5013
> Project: PDFBox
> Issue Type: Bug
> Components: Writing
> Affects Versions: 2.0.20, 2.0.21
> Environment: SpringBoot, JDK1.8
> Reporter: Gilbert
> Priority: Major
> Attachments: screenshot-1.png
>
>
> 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.
>
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]