Home > Software design >  PDFBox: Giving Loop within object COSObject{2, 0}
PDFBox: Giving Loop within object COSObject{2, 0}

Time:07-25

I am using Apache PDFBox to merge different PDF files into one big file. It has been working fine. But recently for one particular file, i have started receiving the below error.

java.io.IOException: Loop within object COSObject{2, 0}
    at org.apache.pdfbox.multipdf.PDFCloneUtility.checkForRecursion(PDFCloneUtility.java:277)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:149)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:109)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:119)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:150)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:109)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:119)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:150)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:109)
    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:150)
    at org.apache.pdfbox.multipdf.PDFMergerUtility.appendDocument(PDFMergerUtility.java:800)
    at org.apache.pdfbox.multipdf.PDFMergerUtility.legacyMergeDocuments(PDFMergerUtility.java:459)
    at org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:346)
    at 

Does anyone has any idea why this might be happening or how to fix this error?

I'm using 2.0.26 version of PDFBox

CodePudding user response:

This is related to a self-reference within an object (shouldn't be!). It was first fixed in PDFBOX-5372 in the way that you're experiencing (IOException), and the fix was improved in PDFBOX-5429 which no longer throws an exception. This will be in 2.0.27 and a snapshot is available here.

  • Related