You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by Eric Eastman <er...@greenfiling.com> on 2011/11/07 16:32:33 UTC

Null Pointer Exception closing PDF

Hello all,

I'm quite new to pdfbox, but very experienced with java and pdf. I am
getting a null pointer exception closing a PDF file. I believe that the
RandomAccessBuffer.close() method is being called before the FlateFilter is
finished writing to it.  Is FlateFilter required?  If not, how can I turn
it off to get past this problem?

I added "super(e);" to :
    public WrappedException( Exception e )
    {
        super(e);
        wrapped = e;
    }
So that the root cause exception would be printed by SLF4J logging.  Is
there some reason that was left off?

If I end up debugging the filter issue, what is the mechanism for
submitting a patch?  Is there an issue tracker for Pdf Box?

I know there are quite a few questions in this email.  Partial responses
welcome?

Thanks,
Eric


Here is the exception I'm getting:
10:07:10.197 [main] DEBUG c.g.reports.PdfOutputWriter - Error Finalizing
report
org.apache.pdfbox.exceptions.COSVisitorException: null
    at
org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1245)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:201)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:524)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:434)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1056)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:456)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1392)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1122)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
com.greenfiling.reports.PdfOutputWriter.completeReport(PdfOutputWriter.java:127)
~[classes/:na]
    at
com.greenfiling.reports.OutputWriterTest.testPdf(OutputWriterTest.java:51)
[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:1.6.0_26]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
~[na:1.6.0_26]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
~[na:1.6.0_26]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.6.0_26]
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
[junit.jar:na]
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
[junit.jar:na]
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
[junit.jar:na]
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
[junit.jar:na]
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
[junit.jar:na]
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
[junit.jar:na]
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
[junit.jar:na]
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
[junit.jar:na]
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
[junit.jar:na]
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
[junit.jar:na]
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
[junit.jar:na]
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
[junit.jar:na]
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
[junit.jar:na]
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
[junit.jar:na]
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
[.cp/:na]
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
[.cp/:na]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
[.cp/:na]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
[.cp/:na]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
[.cp/:na]
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[.cp/:na]
Caused by: java.lang.NullPointerException: null
    at
org.apache.pdfbox.io.RandomAccessBuffer.write(RandomAccessBuffer.java:124)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
org.apache.pdfbox.io.RandomAccessFileOutputStream.write(RandomAccessFileOutputStream.java:110)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at java.util.zip.DeflaterOutputStream.deflate(Unknown Source)
~[na:1.6.0_26]
    at java.util.zip.DeflaterOutputStream.finish(Unknown Source)
~[na:1.6.0_26]
    at java.util.zip.DeflaterOutputStream.close(Unknown Source)
~[na:1.6.0_26]
    at org.apache.pdfbox.filter.FlateFilter.encode(FlateFilter.java:348)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at org.apache.pdfbox.cos.COSStream.doEncode(COSStream.java:366)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at org.apache.pdfbox.cos.COSStream.doEncode(COSStream.java:343)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
org.apache.pdfbox.cos.COSStream.getFilteredStream(COSStream.java:134)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    at
org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1219)
~[pdfbox-1.7.0-SNAPSHOT.jar:1.7.0-SNAPSHOT]
    ... 33 common frames omitted

-- 
Eric Dimick Eastman
Green Filing, LLC

Web: www.greenfiling.com
Phone: (801) 448-7268
Cell: (765) 277-4158

Re: Null Pointer Exception closing PDF

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,

Am 07.11.2011 16:32, schrieb Eric Eastman:
> Hello all,
>
> I'm quite new to pdfbox, but very experienced with java and pdf. I am
> getting a null pointer exception closing a PDF file. I believe that the
> RandomAccessBuffer.close() method is being called before the FlateFilter is
> finished writing to it.  Is FlateFilter required?  If not, how can I turn
> it off to get past this problem?
The filter is used by default to compress the content stream.

Is is not that easy to figure out what went wrong without having some more 
information on your implementation. Are you following the cookbook examples like 
[1] ?

> I added "super(e);" to :
>      public WrappedException( Exception e )
>      {
>          super(e);
>          wrapped = e;
>      }
> So that the root cause exception would be printed by SLF4J logging.  Is
> there some reason that was left off?
>
> If I end up debugging the filter issue, what is the mechanism for
> submitting a patch?  Is there an issue tracker for Pdf Box?
Of course there is [2]

> I know there are quite a few questions in this email.  Partial responses
> welcome?
>
> Thanks,
> Eric
>
>
> Here is the exception I'm getting:
> 10:07:10.197 [main] DEBUG c.g.reports.PdfOutputWriter - Error Finalizing
> report
> org.apache.pdfbox.exceptions.COSVisitorException: null
>      at
<SNIP>


BR
Andreas Lehmkühler
[1] http://pdfbox.apache.org/userguide/cookbook/creation.html#HelloWorld
[2] https://issues.apache.org/jira/browse/PDFBOX