Hello all,

In new release of Apache PDFBox 3.0.7 there is a problem with 
PDDocumentCatalog.setThreads(null).

This worked fine with version 3.0.1 (or at least I think so), but with new 
version it will cause an exception:

java.lang.IllegalArgumentException: List of COSObjectables cannot be null
  at org.apache.pdfbox.cos.COSArray.<init>(COSArray.java:56)
  at 
org.apache.pdfbox.pdmodel.PDDocumentCatalog.setThreads(PDDocumentCatalog.java:241)
  at com.ct.ecm.pdf.PDFCompress.compressPDFbyRemovingInfo(PDFCompress.java:156)

When you look at source code of PDDocumentCatalog, it shows that parameter 
threads can be null:

/**
* Sets the list of threads for this pdf document.
*
* @param threads The list of threads, or null to clear it.
*/
public void setThreads(List<PDThread> threads)
{
    COSArray threadsArray = new COSArray(threads);
    threadsArray.setDirect(false);
    root.setItem(COSName.THREADS, threadsArray);
}

So, it is supposed to accept null as value for threads parameter.
However, the constructor of COSArray class is testing if this argument is null, 
and throws an exception:

/**
* Use the given list to initialize the COSArray.
*
* @param cosObjectables the initial list of COSObjectables
*/
public COSArray(List<? extends COSObjectable> cosObjectables)
{
    if (cosObjectables == null)
    {
        throw new IllegalArgumentException("List of COSObjectables cannot be 
null");
    }
    updateState = new COSUpdateState(this);
    setDirect(true);
    cosObjectables.forEach(cosObjectable ->
        objects.add(cosObjectable != null ? cosObjectable.getCOSObject() : 
null));
}

Please fix this in new version, and for now please tell me the alternative way 
to clear threads in PDDocumentCatalog.


Thank you and best regards,

Predrag

Reply via email to