Hello

One of our users in production received an error with the following stack trace:

java.lang.NullPointerException
        at 
org.apache.pdfbox.multipdf.PDFMergerUtility.mergeAcroForm(PDFMergerUtility.java:678)
        at 
org.apache.pdfbox.multipdf.PDFMergerUtility.appendDocument(PDFMergerUtility.java:366)
        at 
org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:261)
...

Relevant code from our side is:
...
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
      PDFMergerUtility mergerUtility = new PDFMergerUtility();
      mergerUtility.addSource(new ByteArrayInputStream(pdfFileByteArray);
      mergerUtility.addSource(new ByteArrayInputStream(anotherPdfFileByteArray);
      mergerUtility.setDestinationStream(out);
      mergerUtility.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());
...

Digging into the code, I think I have a suspicion of what could be the issue.

...
COSArray destFields = (COSArray) 
destAcroForm.getCOSObject().getItem(COSName.FIELDS);
for (PDField srcField : srcAcroForm.getFieldTree())
{
      ...
      destFields.add(dstField); // exception happens here
}
...

destfields is null because the destination COSObject/Dictionary has no Fields 
key, but the source does.
The destination pdf file is created earlier in the PDDocument constructor, but 
the CosName.FIELDS is not added to it.

Is this a bug, or an improper usage of the PDFBox?
We are using PDFBox 2.0.1. The closest issue I could find was this: 
https://issues.apache.org/jira/browse/PDFBOX-3663
I updated PDFBox to 2.0.5 and checked the code after the update, but it seems 
the constructor still does not set that value.

Kind Regards,

Forgács Péter
Junior Java Developer
[Appello logo]
Madách Trade Center, A building, 2. floor

H-1075 Budapest, Madách Imre út 13-14.
Tel: +36 1 474 0915
[email protected]
www.appello.eu<http://www.appello.eu>
    [cid:[email protected]] 
<https://www.linkedin.com/company/appello---banking-it>     
[cid:[email protected]] 
<https://www.facebook.com/ApPello-Banking-Software-1500303710198451/>

[finovateeurope2019_banner4]<https://appello.eu/appello-demo-presentation-at-finovate-europe-2019/>


Reply via email to