Skip to content

Commit

Permalink
Handle NPE on CopyPagesTo
Browse files Browse the repository at this point in the history
DEVSIX-6298
  • Loading branch information
AnhelinaM committed May 10, 2022
1 parent 22b28c2 commit 30c6c9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ private void addChildToExistingParent(PdfDictionary fieldDic, Set<String> existi
if (existingFields.contains(name)) {
PdfArray kids = parent.getAsArray(PdfName.Kids);
for (PdfObject kid : kids) {
if (((PdfDictionary) kid).get(PdfName.T).equals(fieldDic.get(PdfName.T))) {
if (((PdfDictionary) kid).get(PdfName.T) != null &&
((PdfDictionary) kid).get(PdfName.T).equals(fieldDic.get(PdfName.T))) {
PdfFormField kidField = makeFormField(kid);
PdfFormField field = makeFormField(fieldDic);
if (kidField == null || field == null) {
Expand Down
12 changes: 12 additions & 0 deletions forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -696,4 +696,16 @@ public void mergeTwoWidgetsAndTwoWidgetsTest() throws IOException, InterruptedEx

Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
}

@Test
public void widgetContainsNoTEntryTest() throws IOException, InterruptedException {
String sourceFileName = sourceFolder + "fieldThreeWidgets.pdf";
String destFileName = destinationFolder + "widgetContainsNoTEntryTest.pdf";
String cmpFileName = sourceFolder + "cmp_widgetContainsNoTEntryTest.pdf";
PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(sourceFileName));
PdfDocument resultPdfDocument = new PdfDocument(new PdfWriter(destFileName));
sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(), resultPdfDocument, new PdfPageFormCopier());
resultPdfDocument.close();
Assert.assertNull(new CompareTool().compareByContent(destFileName, cmpFileName, destinationFolder, "diff_"));
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 30c6c9e

Please sign in to comment.