You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Kevin Ternes <KT...@thegeneral.com> on 2015/08/07 23:56:01 UTC

NullPointerException from PDDocument

I have a particular PDF that I have loaded that throws a NullPointerException from PDDocument.getDocumentCatalog().
>From PDDocument:

public PDDocumentCatalog getDocumentCatalog()
{
      If (documentCatalog == null)
      {
            COSDictionary trailer = document.getTrailer();
            COSBase dictionary = trailer.getDictionaryObject( COSName.ROOT );
            if (dictionary instanceof COSDictionary) 
            {
                documentCatalog = new PDDocumentCatalog(this, (COSDictionary) dictionary);
            } 
            else 
            {
                documentCatalog = new PDDocumentCatalog(this);
            }
      }
      return documentCatalog;
}

The document.getTrailer() returns NULL for this PDF and thus the NullPointerException from the next line.

Is it possible that the PDF is malformed?
I do not see where I might have cleared the document.trailer field.

If any PDFBox developers are listening, would it be reasonable to put a check into the above code to deal with the NULL document.trailer?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: NullPointerException from PDDocument

Posted by Kevin Ternes <KT...@thegeneral.com>.
That's why I always travel to Europe when I go on vacation.

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Tuesday, August 11, 2015 12:44 PM
To: users@pdfbox.apache.org
Subject: Re: NullPointerException from PDDocument

We'd probably put some messages everywhere.... please accept that if you do illegal things, mayhem will follow :-)

Tilman


>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Friday, August 07, 2015 5:02 PM
> To: users@pdfbox.apache.org
> Subject: Re: NullPointerException from PDDocument
>
> Can you upload the document somewhere?
>
> Tilman
>
> Am 07.08.2015 um 23:56 schrieb Kevin Ternes:
>> I have a particular PDF that I have loaded that throws a NullPointerException from PDDocument.getDocumentCatalog().
>>   From PDDocument:
>>
>> public PDDocumentCatalog getDocumentCatalog() {
>>         If (documentCatalog == null)
>>         {
>>               COSDictionary trailer = document.getTrailer();
>>               COSBase dictionary = trailer.getDictionaryObject( COSName.ROOT );
>>               if (dictionary instanceof COSDictionary)
>>               {
>>                   documentCatalog = new PDDocumentCatalog(this, (COSDictionary) dictionary);
>>               }
>>               else
>>               {
>>                   documentCatalog = new PDDocumentCatalog(this);
>>               }
>>         }
>>         return documentCatalog;
>> }
>>
>> The document.getTrailer() returns NULL for this PDF and thus the NullPointerException from the next line.
>>
>> Is it possible that the PDF is malformed?
>> I do not see where I might have cleared the document.trailer field.
>>
>> If any PDFBox developers are listening, would it be reasonable to put a check into the above code to deal with the NULL document.trailer?
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointerException from PDDocument

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 10.08.2015 um 16:25 schrieb Kevin Ternes:
> Thanks Tilman, but I found the problem.  It is not a malformed PDF.
> The PDDocument was being prematurely closed in an earlier method.
>
> I still think it would be good if this method added a description message about the null trailer to the Exception.  With an ordinary NullPointerException, we really have no idea what might have happened.

We'd probably put some messages everywhere.... please accept that if you 
do illegal things, mayhem will follow :-)

Tilman


>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Friday, August 07, 2015 5:02 PM
> To: users@pdfbox.apache.org
> Subject: Re: NullPointerException from PDDocument
>
> Can you upload the document somewhere?
>
> Tilman
>
> Am 07.08.2015 um 23:56 schrieb Kevin Ternes:
>> I have a particular PDF that I have loaded that throws a NullPointerException from PDDocument.getDocumentCatalog().
>>   From PDDocument:
>>
>> public PDDocumentCatalog getDocumentCatalog() {
>>         If (documentCatalog == null)
>>         {
>>               COSDictionary trailer = document.getTrailer();
>>               COSBase dictionary = trailer.getDictionaryObject( COSName.ROOT );
>>               if (dictionary instanceof COSDictionary)
>>               {
>>                   documentCatalog = new PDDocumentCatalog(this, (COSDictionary) dictionary);
>>               }
>>               else
>>               {
>>                   documentCatalog = new PDDocumentCatalog(this);
>>               }
>>         }
>>         return documentCatalog;
>> }
>>
>> The document.getTrailer() returns NULL for this PDF and thus the NullPointerException from the next line.
>>
>> Is it possible that the PDF is malformed?
>> I do not see where I might have cleared the document.trailer field.
>>
>> If any PDFBox developers are listening, would it be reasonable to put a check into the above code to deal with the NULL document.trailer?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: NullPointerException from PDDocument

Posted by Kevin Ternes <KT...@thegeneral.com>.
Thanks Tilman, but I found the problem.  It is not a malformed PDF.
The PDDocument was being prematurely closed in an earlier method.

I still think it would be good if this method added a description message about the null trailer to the Exception.  With an ordinary NullPointerException, we really have no idea what might have happened.

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Friday, August 07, 2015 5:02 PM
To: users@pdfbox.apache.org
Subject: Re: NullPointerException from PDDocument

Can you upload the document somewhere?

Tilman

Am 07.08.2015 um 23:56 schrieb Kevin Ternes:
> I have a particular PDF that I have loaded that throws a NullPointerException from PDDocument.getDocumentCatalog().
>  From PDDocument:
>
> public PDDocumentCatalog getDocumentCatalog() {
>        If (documentCatalog == null)
>        {
>              COSDictionary trailer = document.getTrailer();
>              COSBase dictionary = trailer.getDictionaryObject( COSName.ROOT );
>              if (dictionary instanceof COSDictionary)
>              {
>                  documentCatalog = new PDDocumentCatalog(this, (COSDictionary) dictionary);
>              }
>              else
>              {
>                  documentCatalog = new PDDocumentCatalog(this);
>              }
>        }
>        return documentCatalog;
> }
>
> The document.getTrailer() returns NULL for this PDF and thus the NullPointerException from the next line.
>
> Is it possible that the PDF is malformed?
> I do not see where I might have cleared the document.trailer field.
>
> If any PDFBox developers are listening, would it be reasonable to put a check into the above code to deal with the NULL document.trailer?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointerException from PDDocument

Posted by Tilman Hausherr <TH...@t-online.de>.
Can you upload the document somewhere?

Tilman

Am 07.08.2015 um 23:56 schrieb Kevin Ternes:
> I have a particular PDF that I have loaded that throws a NullPointerException from PDDocument.getDocumentCatalog().
>  From PDDocument:
>
> public PDDocumentCatalog getDocumentCatalog()
> {
>        If (documentCatalog == null)
>        {
>              COSDictionary trailer = document.getTrailer();
>              COSBase dictionary = trailer.getDictionaryObject( COSName.ROOT );
>              if (dictionary instanceof COSDictionary)
>              {
>                  documentCatalog = new PDDocumentCatalog(this, (COSDictionary) dictionary);
>              }
>              else
>              {
>                  documentCatalog = new PDDocumentCatalog(this);
>              }
>        }
>        return documentCatalog;
> }
>
> The document.getTrailer() returns NULL for this PDF and thus the NullPointerException from the next line.
>
> Is it possible that the PDF is malformed?
> I do not see where I might have cleared the document.trailer field.
>
> If any PDFBox developers are listening, would it be reasonable to put a check into the above code to deal with the NULL document.trailer?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org