@@ -43,6 +43,8 @@ This file is part of the iText (R) project.
4343package com .itextpdf .kernel .pdf ;
4444
4545import com .itextpdf .io .LogMessageConstant ;
46+ import com .itextpdf .io .util .MessageFormatUtil ;
47+ import com .itextpdf .kernel .PdfException ;
4648import com .itextpdf .kernel .pdf .navigation .PdfDestination ;
4749import com .itextpdf .kernel .pdf .navigation .PdfExplicitDestination ;
4850import com .itextpdf .kernel .pdf .navigation .PdfStringDestination ;
@@ -52,6 +54,8 @@ This file is part of the iText (R) project.
5254import com .itextpdf .test .annotations .LogMessages ;
5355import com .itextpdf .test .annotations .type .IntegrationTest ;
5456
57+ import java .io .ByteArrayOutputStream ;
58+ import java .util .HashMap ;
5559import org .xml .sax .SAXException ;
5660import javax .xml .parsers .ParserConfigurationException ;
5761import java .io .FileOutputStream ;
@@ -508,4 +512,56 @@ public void removePageInDocWithComplexOutlineTreeStructTest() throws IOException
508512
509513 Assert .assertNull (new CompareTool ().compareByContent (output , cmp , DESTINATION_FOLDER , "diff_" ));
510514 }
515+
516+ @ Test
517+ public void constructOutlinesNoParentTest () throws IOException {
518+ try (
519+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
520+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (baos ))) {
521+ pdfDocument .addNewPage ();
522+
523+ PdfDictionary first = new PdfDictionary ();
524+ first .makeIndirect (pdfDocument );
525+
526+ PdfDictionary outlineDictionary = new PdfDictionary ();
527+ outlineDictionary .put (PdfName .First , first );
528+
529+ Exception exception = Assert .assertThrows (
530+ PdfException .class ,
531+ () -> pdfDocument .getCatalog ().constructOutlines (outlineDictionary , new HashMap <String , PdfObject >())
532+ );
533+ Assert .assertEquals (
534+ MessageFormatUtil .format (PdfException .CORRUPTED_OUTLINE_NO_PARENT_ENTRY ,
535+ first .indirectReference ),
536+ exception .getMessage ());
537+ }
538+ }
539+
540+ @ Test
541+ public void constructOutlinesNoTitleTest () throws IOException {
542+ try (
543+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
544+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (baos ))) {
545+ pdfDocument .addNewPage ();
546+
547+ PdfDictionary first = new PdfDictionary ();
548+ first .makeIndirect (pdfDocument );
549+
550+ PdfDictionary outlineDictionary = new PdfDictionary ();
551+ outlineDictionary .makeIndirect (pdfDocument );
552+
553+ outlineDictionary .put (PdfName .First , first );
554+ first .put (PdfName .Parent , outlineDictionary );
555+
556+ Exception exception = Assert .assertThrows (
557+ PdfException .class ,
558+ () -> pdfDocument .getCatalog ()
559+ .constructOutlines (outlineDictionary , new HashMap <String , PdfObject >())
560+ );
561+ Assert .assertEquals (
562+ MessageFormatUtil .format (PdfException .CORRUPTED_OUTLINE_NO_TITLE_ENTRY ,
563+ first .indirectReference ),
564+ exception .getMessage ());
565+ }
566+ }
511567}
0 commit comments