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 2BB8E17BAB for ; Tue, 8 Sep 2015 14:46:56 +0000 (UTC) Received: (qmail 30271 invoked by uid 500); 8 Sep 2015 14:46:43 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 30248 invoked by uid 500); 8 Sep 2015 14:46:43 -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 30237 invoked by uid 99); 8 Sep 2015 14:46:43 -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 14:46:43 +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 B1F93E0266 for ; Tue, 8 Sep 2015 14:46:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1 X-Spam-Level: * X-Spam-Status: No, score=1 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1] autolearn=disabled Received: from mx1-eu-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 iHviAytm_1Vd for ; Tue, 8 Sep 2015 14:46:41 +0000 (UTC) Received: from us-smtp-delivery-105.mimecast.com (us-smtp-delivery-105.mimecast.com [216.205.24.105]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 703CF20382 for ; Tue, 8 Sep 2015 14:46:40 +0000 (UTC) Received: from hubca1.pgac.com (email.pgac.com [12.68.231.192]) (Using TLS) by us-smtp-1.mimecast.com with ESMTP id us-mta-35-OmIXIp5SSoy0ioAc-4J68g-67; Tue, 08 Sep 2015 10:46:31 -0400 Received: from EX07MAIL3.pgac.com ([172.23.10.5]) by hubca1.pgac.com ([172.23.10.3]) with mapi; Tue, 8 Sep 2015 09:45:12 -0500 From: Kevin Ternes To: "users@pdfbox.apache.org" Date: Tue, 8 Sep 2015 09:45:11 -0500 Subject: Best way to deal with NULL PDAcroForm fields Thread-Topic: Best way to deal with NULL PDAcroForm fields Thread-Index: AdDqRPOlKjFxtrDtQ0i25L/IUxOvEQ== Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-MC-Unique: OmIXIp5SSoy0ioAc-4J68g-67 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable 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 =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:{ To avoid this, at first I was calling PDAcroForm.getFields() and checking t= hat to see if that was NULL but I realized that it would usually create a n= ew fields array to return which seemed wasteful. Is the most efficient way to avoid this to first call: COSArray fields =3D (COSArray) acroForm.getDictionaryObject( COSName.g= etPDFName("Fields")); myself and check if that is NULL?=20 Secondary Question: The method PDAcroForm.getFields() does a not-NULL check of fields before ca= lling fields.size(). Is there a reason that this check is not performed in getField()? --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org