Return-Path: X-Original-To: apmail-pdfbox-users-archive@www.apache.org Delivered-To: apmail-pdfbox-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E0A6F1082D for ; Tue, 8 Sep 2015 17:59:51 +0000 (UTC) Received: (qmail 73301 invoked by uid 500); 8 Sep 2015 17:59:35 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 73276 invoked by uid 500); 8 Sep 2015 17:59:35 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 73265 invoked by uid 99); 8 Sep 2015 17:59:35 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Sep 2015 17:59:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E5A88E033C for ; Tue, 8 Sep 2015 17:59:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.801 X-Spam-Level: * X-Spam-Status: No, score=1.801 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id rpWCZzIj1Ink for ; Tue, 8 Sep 2015 17:59:23 +0000 (UTC) Received: from www168.your-server.de (www168.your-server.de [213.133.104.168]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 6C22720562 for ; Tue, 8 Sep 2015 17:59:23 +0000 (UTC) Received: from [88.198.220.132] (helo=sslproxy03.your-server.de) by www168.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.80.1) (envelope-from ) id 1ZZNAp-0006ND-L2 for users@pdfbox.apache.org; Tue, 08 Sep 2015 19:59:15 +0200 Received: from [80.187.113.127] (helo=[172.20.10.2]) by sslproxy03.your-server.de with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.80) (envelope-from ) id 1ZZNAm-00063l-7s for users@pdfbox.apache.org; Tue, 08 Sep 2015 19:59:12 +0200 Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Subject: Re: Best way to deal with NULL PDAcroForm fields From: Maruan Sahyoun In-Reply-To: Date: Tue, 8 Sep 2015 19:59:08 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <869061B9-BA25-4766-AE49-42B47F1883D9@fileaffairs.de> References: To: users@pdfbox.apache.org X-Mailer: Apple Mail (2.2104) X-Authenticated-Sender: sahyoun@fileaffairs.de X-Virus-Scanned: Clear (ClamAV 0.98.7/20890/Tue Sep 8 14:49:23 2015) Hi, > Am 08.09.2015 um 18:38 schrieb Kevin Ternes : >=20 > 1.8.10 I added a fix for 1.8.11 Thanks for the report - Maruan >=20 > -----Original Message----- > From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de]=20 > Sent: Tuesday, September 08, 2015 11:20 AM > To: users@pdfbox.apache.org > Subject: Re: Best way to deal with NULL PDAcroForm fields >=20 > Hi Kevin, >=20 >> Am 08.09.2015 um 16:45 schrieb Kevin Ternes : >>=20 >>=20 >> 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: >>=20 >> 287: COSArray fields =3D >> 288: (COSArray) acroForm.getDictionaryObject( >> 289: COSName.getPDFName("Fields")); >> 290: >> 291: for (int i =3D 0; i < fields.size() && retval =3D=3D null; i++) = 292:{ >>=20 >> 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. >>=20 >> Is the most efficient way to avoid this to first call: >> COSArray fields =3D (COSArray) acroForm.getDictionaryObject(=20 >> COSName.getPDFName("Fields")); myself and check if that is NULL? >>=20 >>=20 >> 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()? >=20 >=20 > which version of PDFBox are you using? >=20 > BR > Maruan >=20 >>=20 >>=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org >> For additional commands, e-mail: users-help@pdfbox.apache.org >>=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org