PDFBox Version 3.0.0 Please help. Trying to split a pdf file and throwing an exception: java.lang.NullPointerException at org.apache.pdfbox.cos.COSArray.getIndirectObjectKeys(COSArray.java:768)

the reason it is failing at this line is because: 766:for (COSBase cosBase : objects) 767: { 768: COSObjectKey cosBaseKey = cosBase.getKey(); coseBase is null and that's why getKey() fails. There should be a test for null to prevent this. The objects array contains: [null, COSName{XYZ}, COSFloat{80.787}, COSFloat{686.677}, COSNull{}]

Also, the getIndirectObjectKeys method at line 748 only checks for null and the pdf file I am splitting the indirectObjects array is not null but empty; i.e., [] The code should test for emptiness not just nullity.

746:public void getIndirectObjectKeys(List<COSObjectKey> indirectObjects) 747: { 758: if (indirectObjects == null)

The issue here is with the PDFBox Splitter class code.

Is there any way to circumvent this? Thanks very much for your help

I was trying to split a pdf file

1

There are 1 best solutions below

1
On

I can confirm the first reported issue in line 768. IMHO the second one can't happen as only not null values are added to the list in question.

I've created the ticket https://issues.apache.org/jira/browse/PDFBOX-5707. Please add a sample pdf for the second issue if availbale. I'm happy to correct my statement from above ;-)