File tree Expand file tree Collapse file tree
main/java/org/apache/pdfbox/pdmodel
test/java/org/apache/pdfbox/pdmodel Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,6 +238,11 @@ public List<PDThread> getThreads()
238238 */
239239 public void setThreads (List <PDThread > threads )
240240 {
241+ if (threads == null )
242+ {
243+ root .removeItem (COSName .THREADS );
244+ return ;
245+ }
241246 COSArray threadsArray = new COSArray (threads );
242247 threadsArray .setDirect (false );
243248 root .setItem (COSName .THREADS , threadsArray );
Original file line number Diff line number Diff line change @@ -685,6 +685,11 @@ public List<PDThreadBead> getThreadBeads()
685685 */
686686 public void setThreadBeads (List <PDThreadBead > beads )
687687 {
688+ if (beads == null )
689+ {
690+ page .removeItem (COSName .B );
691+ return ;
692+ }
688693 page .setItem (COSName .B , new COSArray (beads ));
689694 }
690695
Original file line number Diff line number Diff line change 1818
1919import java .io .IOException ;
2020import java .io .InputStream ;
21+ import java .util .ArrayList ;
2122import java .util .List ;
2223
2324import org .apache .pdfbox .Loader ;
@@ -164,4 +165,19 @@ void handleBooleanInOpenAction() throws IOException
164165 assertNull (doc .getDocumentCatalog ().getOpenAction ());
165166 }
166167 }
168+
169+ @ Test
170+ void testNullThreads () throws IOException
171+ {
172+ // PDFBOX-6186
173+ try (PDDocument doc = new PDDocument ())
174+ {
175+ PDDocumentCatalog documentCatalog = doc .getDocumentCatalog ();
176+ assertEquals (0 , documentCatalog .getThreads ().size ());
177+ documentCatalog .setThreads (new ArrayList <>());
178+ assertEquals (0 , documentCatalog .getThreads ().size ());
179+ documentCatalog .setThreads (null );
180+ assertEquals (0 , documentCatalog .getThreads ().size ());
181+ }
182+ }
167183}
Original file line number Diff line number Diff line change 1818
1919import java .io .ByteArrayOutputStream ;
2020import java .io .IOException ;
21+ import java .util .ArrayList ;
2122
2223import org .apache .pdfbox .pdmodel .common .PDRectangle ;
2324import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotationWidget ;
2425import org .apache .pdfbox .pdmodel .interactive .form .PDAcroForm ;
2526import org .apache .pdfbox .pdmodel .interactive .form .PDTextField ;
27+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2628
2729import org .junit .jupiter .api .Test ;
2830
29- /**
30- * Test case introduced with PDFBOX-6097
31- *
32- */
3331class TestPDPage
3432{
3533 @ Test
3634 void testAddingPageAfterCreatingAnnotation () throws IOException
3735 {
36+ // PDFBOX-6097
3837 try (PDDocument document = new PDDocument ())
3938 {
4039 PDPage page = new PDPage (PDRectangle .A4 );
@@ -58,5 +57,19 @@ void testAddingPageAfterCreatingAnnotation() throws IOException
5857 document .close ();
5958 }
6059 }
61-
60+
61+ @ Test
62+ void testNullThreadBeads () throws IOException
63+ {
64+ // PDFBOX-6186
65+ try (PDDocument document = new PDDocument ())
66+ {
67+ PDPage page = new PDPage ();
68+ assertEquals (0 , page .getThreadBeads ().size ());
69+ page .setThreadBeads (new ArrayList <>());
70+ assertEquals (0 , page .getThreadBeads ().size ());
71+ page .setThreadBeads (null );
72+ assertEquals (0 , page .getThreadBeads ().size ());
73+ }
74+ }
6275}
You can’t perform that action at this time.
0 commit comments