You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Norman Gray (JIRA)" <ji...@apache.org> on 2008/10/05 20:37:44 UTC
[jira] Commented: (PDFBOX-382) PDDocument apparently unclosed even
after calling close()
[ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12636926#action_12636926 ]
Norman Gray commented on PDFBOX-382:
------------------------------------
Arghhh. The bug's invalid.
load() is a static method on PDDocument, thus in the original version, the 'doc' which was being worked on, and closed, was not the thing created by 'new PDDocument'
Oh well....
> PDDocument apparently unclosed even after calling close()
> ---------------------------------------------------------
>
> Key: PDFBOX-382
> URL: https://issues.apache.org/jira/browse/PDFBOX-382
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 0.7.3
> Environment: OS X 10.5.5, Java 1.5.0_16
> Reporter: Norman Gray
> Fix For: 0.7.3
>
>
> I can open a PDDocument, extract information from it, and then close it. However if I then open another PDDocument, I get an exception 'You did not close the PDF Document'. Looking at the relevant code in incubator svn, nothing stands out as being obviously wrong.
> To reproduce:
> % cat PDFBoxBugReduction.java
> import org.pdfbox.pdmodel.PDDocument;
> import org.pdfbox.pdmodel.PDDocumentInformation;
> public class PDFBoxBugReduction {
> public static void main(String[] args) {
> for (String s : args) {
> PDFBoxBugReduction fi = new PDFBoxBugReduction(s);
> System.err.println("File " + s);
> }
> }
>
> public PDFBoxBugReduction(String filename) {
> PDDocument doc = null;
> try {
> try {
> doc = new PDDocument().load(filename);
> PDDocumentInformation info = doc.getDocumentInformation();
> } finally {
> if (doc != null) {
> System.err.println("Closing document " + filename + "...");
> org.pdfbox.cos.COSDocument cos = doc.getDocument();
> cos.close();
> System.err.println("Closed " + cos);
> doc.close();
> }
>
> }
>
> } catch (java.io.IOException e) {
> System.err.println("IOException=" + e);
> System.exit(1);
> }
> }
> }
> % java -version
> java version "1.5.0_16"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
> Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
> % javac -cp PDFBox-0.7.3.jar PDFBoxBugReduction.java
> % java -cp PDFBox-0.7.3.jar:. PDFBoxBugReduction ../part1.pdf ../part2.pdf
> Closing document ../part1.pdf...
> Closed org.pdfbox.cos.COSDocument@2a54f9
> File ../part1.pdf
> java.lang.Throwable: Warning: You did not close the PDF Document
> at org.pdfbox.cos.COSDocument.finalize(COSDocument.java:418)
> at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
> at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
> at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
> at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
> Closing document ../part2.pdf...
> Closed org.pdfbox.cos.COSDocument@6672d6
> File ../part2.pdf
> %
> Oddly, replacing
>
> doc = new PDDocument().load(filename);
> by
> doc = new PDDocument();
> doc.load(filename);
> ...makes the problem go away. Is the wrong thing perhaps being returned by load()?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.