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:12:44 UTC

[jira] Created: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

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


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.


[jira] Updated: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Thomas Modeneis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Modeneis updated PDFBOX-382:
-----------------------------------

    Attachment: ThomasTest.java

Hey Norman, 

Thanks for your answer...

So, ive made some simple example to reproduce the bug... and you can execute it on your eclipse to reproduce the reported bug.

Regards,

Thomas Modeneis.



> 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
>
>         Attachments: ThomasTest.java
>
>
> 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.


[jira] Commented: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Thomas Modeneis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12704135#action_12704135 ] 

Thomas Modeneis commented on PDFBOX-382:
----------------------------------------

I cant re-open this issue, cause the re-open button dont appears here.

Do you want that i make another issue reporting this bug ?

Regards,

Thomas.


> 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
>
>         Attachments: ThomasTest.java
>
>
> 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.


[jira] Updated: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler updated PDFBOX-382:
--------------------------------------

             Priority: Minor  (was: Major)
    Affects Version/s:     (was: 0.7.3)
                       0.8.0-incubator
        Fix Version/s:     (was: 0.7.3)

Changed priority to minor, affected version to 0.8.0 and deleted fixed version

> 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.8.0-incubator
>         Environment: OS X 10.5.5, Java 1.5.0_16
>            Reporter: Norman Gray
>            Priority: Minor
>         Attachments: ThomasTest.java
>
>
> 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.


[jira] Resolved: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Norman Gray (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Norman Gray resolved PDFBOX-382.
--------------------------------

       Resolution: Invalid
    Fix Version/s: 0.7.3

Closed by submitter as invalid

> 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.


[jira] Commented: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Norman Gray (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12704121#action_12704121 ] 

Norman Gray commented on PDFBOX-382:
------------------------------------

I'm no longer really working on this topic, so I can't really comment.  I'll leave it to you to reopen the bug, if you feel it is after all invalid.  It certainly seems that there is at least something a little odd about the return value of load()

All the best,

Norman


> 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.


[jira] Commented: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Norman Gray (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Thomas Modeneis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12704099#action_12704099 ] 

Thomas Modeneis commented on PDFBOX-382:
----------------------------------------

This bug is not invalid, this bug really exists:

take a loook at this two methods:

public static PDDocument loadPdfFromByte(byte [] pdf){
PDDocument document = null; 
try {
document = PDDocument.load(new ByteArrayInputStream(pdf));
} catch (IOException e) {} 
return document;
}

--

public static List<PDPage> getAllPages(PDDocument document){
int numberOfPages = document.getNumberOfPages();
List<PDPage> paginas = new ArrayList<PDPage>();
List pages = document.getDocumentCatalog().getAllPages();
for (int i = 0; i < numberOfPages; i++) {
paginas.add((PDPage)pages.get(i));
}
return paginas;
}

--

so, after i got document reference i will try to use, paginate and add another´s to them...

PDDocument document = PDFUtils.loadPdfFromByte(pdf); 
List<PDPage> paginas = PDFUtils.getAllPages(document);
for(PDPage pagina:paginas){
document.addPage(pagina);
}	

and after two or tree times that i add pages to docFinal, this exception allways appears on log:

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)


so,  if i try to close document....and then add pages to ANOTHER document reference....

like this:

public void addPagesToDocument(PDDocument docFinal,byte[] pdf){
PDDocument document = PDFUtils.loadPdfFromByte(pdf); 
List<PDPage> paginas = PDFUtils.getAllPages(document);
PDFUtils.close(document);
for(PDPage pagina:paginas){
docFinal.addPage(pagina);
}	
}

then i cant create valid PDF...

this exception appears to me when i try to save:

docFinal.save(outputStream);		

Exception:

"org.pdfbox.exceptions.COSVisitorException: invalid identifier"



i dont think this is not a bug.....cause for me, it appears to be like a bug.


regards,

Thomas.


> 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.


[jira] Reopened: (PDFBOX-382) PDDocument apparently unclosed even after calling close()

Posted by "Norman Gray (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Norman Gray reopened PDFBOX-382:
--------------------------------


Reopened following above comments by Thomas Modeneis.

I notice that the priority is currently 'major'; that's perhaps a trifle strong, and I would make no objection to it being lowered.

> 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
>
>         Attachments: ThomasTest.java
>
>
> 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.