Affects Version/s: 1.8.1
Fix Version/s: None
Getting the following stacktrace:
org.apache.pdfbox.exceptions.COSVisitorException: java.lang.IndexOutOfBoundsException: Index: 28, Size: 0
Caused by: java.lang.IndexOutOfBoundsException: Index: 28, Size: 0
I'll add some context. We have a "data pipeline" in which a Windows Print Monitor sends postscript into a servlet which then uses GhostScript 9.05 to convert in-memory to PDF. This PDF is then loaded into PDFBox using PDDocument.load().
At this point we split the original PDF into multiple smaller ones each of which is saved to a ByteArrayOutputStream. At the point of save() we are having serious reliability issues.
Taking an original PDF from Ghostscript we have saved this into a unit test to replicate the problem without success. If we attempt to re-execute the pipeline to take the original PDF and split it, we get apparently random percentages of saved documents.
For instance, on a 990 page document (text, no images), to be split into 990 1-page documents using Tomcat 7 with -Xmx=512m:
Pass 1: 50% were saved, 50% ended with stack traces
Pass 2: 100% were saved
Pass 3: 100% were saved
The same test with -Xmx=128m ended several times with just 1 document saved, the rest were stack traces.
We have also seen this randomly hit a sample document consisting of four pages to be split into two two-page documents so it does not appear to be memory related. We also added code to catch the IndexOutOfBoundsException and make up to ten attempts to repeat, but it seems the save() either works the first time or not at all.
We're thinking there are environmental factors here but we're now focused on getting this nailed. Any advice or assistance will be welcomed.