Skip to content

Commit 30c6c9e

Browse files
committed
Handle NPE on CopyPagesTo
DEVSIX-6298
1 parent 22b28c2 commit 30c6c9e

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

forms/src/main/java/com/itextpdf/forms/PdfPageFormCopier.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ private void addChildToExistingParent(PdfDictionary fieldDic, Set<String> existi
335335
if (existingFields.contains(name)) {
336336
PdfArray kids = parent.getAsArray(PdfName.Kids);
337337
for (PdfObject kid : kids) {
338-
if (((PdfDictionary) kid).get(PdfName.T).equals(fieldDic.get(PdfName.T))) {
338+
if (((PdfDictionary) kid).get(PdfName.T) != null &&
339+
((PdfDictionary) kid).get(PdfName.T).equals(fieldDic.get(PdfName.T))) {
339340
PdfFormField kidField = makeFormField(kid);
340341
PdfFormField field = makeFormField(fieldDic);
341342
if (kidField == null || field == null) {

forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -696,4 +696,16 @@ public void mergeTwoWidgetsAndTwoWidgetsTest() throws IOException, InterruptedEx
696696

697697
Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
698698
}
699+
700+
@Test
701+
public void widgetContainsNoTEntryTest() throws IOException, InterruptedException {
702+
String sourceFileName = sourceFolder + "fieldThreeWidgets.pdf";
703+
String destFileName = destinationFolder + "widgetContainsNoTEntryTest.pdf";
704+
String cmpFileName = sourceFolder + "cmp_widgetContainsNoTEntryTest.pdf";
705+
PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(sourceFileName));
706+
PdfDocument resultPdfDocument = new PdfDocument(new PdfWriter(destFileName));
707+
sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(), resultPdfDocument, new PdfPageFormCopier());
708+
resultPdfDocument.close();
709+
Assert.assertNull(new CompareTool().compareByContent(destFileName, cmpFileName, destinationFolder, "diff_"));
710+
}
699711
}
Binary file not shown.

0 commit comments

Comments
 (0)