Moritz Orth created PDFBOX-3663:
-----------------------------------
Summary: NullPointerException when signing a PDF with AcroForm and
no fields
Key: PDFBOX-3663
URL: https://issues.apache.org/jira/browse/PDFBOX-3663
Project: PDFBox
Issue Type: Bug
Components: AcroForm
Affects Versions: 2.1.0
Reporter: Moritz Orth
This is related to PDFBOX-1719. The workaround made there calls
PDAcroForm.setFields with an empty list when the acro form has no fields:
{code:title=PDDocument.java (Line 286)|borderStyle=solid}
List<PDField> fields = acroForm.getFields();
if (fields == null)
{
fields = new ArrayList<PDField>();
acroForm.setFields(fields);
}
else
{
COSArray fieldArray = (COSArray)
acroForm.getCOSObject().getDictionaryObject(COSName.FIELDS);
fieldArray.setNeedToBeUpdated(true);
}
{code}
This doesn't work anymore because PDAcroFrom.getFields never returns null in
the current version, instead it returns an empty list and a NPE raises in line
295.
The source of the problem seems to be that the PDAcroForm's dictionary's
COSName.FIELDS field contains null instead of an empty array. An empty array is
implicitly created when calling PDAcroForm.setFields with an empty list. The
PDAcroForm(PDDocument) constructor also sets an empty COSArray for the field.
You could also do this in the second constrcutor, that would fix the error:
{code:title=PDAcroForm.java|borderStyle=solid}
public PDAcroForm(PDDocument doc, COSDictionary form)
{
document = doc;
dictionary = form;
if (dictionary.getItem(COSName.FIELDS) == null)
{
dictionary.setItem(COSName.FIELDS, new COSArray());
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]