You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Maruan Sahyoun (JIRA)" <ji...@apache.org> on 2015/09/08 19:37:46 UTC

[jira] [Commented] (PDFBOX-2965) NPE in PDAcroForm.getField() if the /Fields entry is missing

    [ https://issues.apache.org/jira/browse/PDFBOX-2965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14735232#comment-14735232 ] 

Maruan Sahyoun commented on PDFBOX-2965:
----------------------------------------

Simple code to replicate the issue:

{code}
PDDocument doc = new PDDocument();
PDAcroForm form = new PDAcroForm(doc);
doc.getDocumentCatalog().setAcroForm(form);
// this returns null
form.getField("foo");

form.getDictionary().removeItem(COSName.FIELDS);
// this causes an NPE
form.getField("foo");
{code}

> NPE in PDAcroForm.getField() if the /Fields entry is missing
> ------------------------------------------------------------
>
>                 Key: PDFBOX-2965
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2965
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 1.8.10
>            Reporter: Maruan Sahyoun
>             Fix For: 1.8.11
>
>
> Form the users mailing list
> {quote}
> I get a lot of weird documents.  When I try to set a particular field value, some of them throw NullPointerExceptions from line PDAcroForm.getField(), line 291:
> 287: COSArray fields =
> 288:    (COSArray) acroForm.getDictionaryObject(
> 289:        COSName.getPDFName("Fields"));
> 290:
> 291: for (int i = 0; i < fields.size() && retval == null; i++)
> 292:{
> To avoid this, at first I was calling PDAcroForm.getFields() and checking that to see if that was NULL but I realized that it would usually create a new fields array to return which seemed wasteful.
> Is the most efficient way to avoid this to first call:
>    COSArray fields =  (COSArray) acroForm.getDictionaryObject( COSName.getPDFName("Fields"));
> myself and check if that is NULL? 
> Secondary Question:
> The method PDAcroForm.getFields() does a not-NULL check of fields before calling fields.size().
> Is there a reason that this check is not performed in getField()?
> {quote}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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