Skip to content

Commit 7c60c14

Browse files
committed
Do not copy destination if it is null
DEVSIX-3633
1 parent 1176bc4 commit 7c60c14

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfCatalog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ void addRootOutline(PdfOutline outline) {
562562
}
563563

564564
PdfDestination copyDestination(PdfObject dest, Map<PdfPage, PdfPage> page2page, PdfDocument toDocument) {
565+
if (null == dest) {
566+
return null;
567+
}
565568
PdfDestination d = null;
566569
if (dest.isArray()) {
567570
PdfObject pageObject = ((PdfArray) dest).get(0);

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfDestinationTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ This file is part of the iText (R) project.
6060
import com.itextpdf.test.annotations.type.IntegrationTest;
6161

6262
import java.io.ByteArrayOutputStream;
63+
import java.util.HashMap;
6364
import org.junit.Assert;
6465
import org.junit.BeforeClass;
6566
import org.junit.Test;
@@ -407,4 +408,19 @@ public void remoteGoToNotValidExplicitDestinationTest() throws IOException, Inte
407408

408409
assertNull(new CompareTool().compareByContent(outFile, cmpFile, destinationFolder, "diff_"));
409410
}
411+
412+
@Test
413+
public void copyNullDestination() throws IOException {
414+
try (
415+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
416+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(baos))) {
417+
pdfDocument.addNewPage();
418+
419+
PdfDestination copiedDestination = pdfDocument.getCatalog()
420+
.copyDestination(null, new HashMap<PdfPage, PdfPage>(), pdfDocument);
421+
422+
// We expect null to be returned if the destination to be copied is null
423+
Assert.assertNull(copiedDestination);
424+
}
425+
}
410426
}

0 commit comments

Comments
 (0)