[
https://issues.apache.org/jira/browse/PDFBOX-3663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15839914#comment-15839914
]
ASF subversion and git services commented on PDFBOX-3663:
---------------------------------------------------------
Commit 1780416 from [~tilman] in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1780416 ]
PDFBOX-3663: clarify javadoc
> 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
> Assignee: Tilman Hausherr
> Fix For: 2.0.5, 2.1.0
>
>
> 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]