Could not load com.sun.media.imageio.plugins.tiff.TIFFImageReadParam

Hello everyone,

We are using Aspose to sign documents for a public hospital.
It used to work fine but now, it randomly fails and when we check the document we get an empty PDF file.

This is the error message:

04, 2021 12:09:57 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFOS: Illegal access: this web application instance has been stopped already. Could not load com.sun.media.imageio.plugins.tiff.TIFFImageReadParam. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi.createReaderInstance(TIFFImageReaderSpi.java:116)
at javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at com.aspose.pdf.internal.p657.z1$z4.m1(Unknown Source)
at com.aspose.pdf.internal.p657.z1$z1.m1(Unknown Source)
at com.aspose.pdf.internal.p657.z1$z1.m1(Unknown Source)
at com.aspose.pdf.internal.p657.z1.m4(Unknown Source)
at com.aspose.pdf.internal.p618.z30.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m2(Unknown Source)
at com.aspose.pdf.XImageCollection.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m1(Unknown Source)
at com.aspose.pdf.XImageCollection.m2(Unknown Source)
at com.aspose.pdf.SignatureField.m1(Unknown Source)
at com.aspose.pdf.SignatureField.sign(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.m1(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.save(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.save(Unknown Source)
at signpdf.sign(signpdf.java:39)
at jqs.doPost(jqs.java:347)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

And this is the Java code we use to sign the PDF file:

import java.io.*;
import com.aspose.pdf.Document;
import com.aspose.pdf.DocSaveOptions;
import com.aspose.pdf.facades.PdfFileSignature;
import com.aspose.pdf.PKCS1;

public class signpdf
{
    public static void sign(String filename) 
    {
        try
        {
        com.aspose.pdf.License pdfLicense = new com.aspose.pdf.License();
        pdfLicense.setLicense(par.repSign + "Aspose.Total.Java.lic");

        Document doc = new Document(filename); 

        // Add a page to PDF document
        doc.getPages().add();
        OutputStream out = new java.io.ByteArrayOutputStream();
        // Save document to Stream object
        doc.save(out);

        // Create PdfFileSignature instance
        PdfFileSignature pdfSignSingle = new PdfFileSignature();
        // Bind the source PDF by reading contents of Stream
        pdfSignSingle.bindPdf(new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray()));

        // Sign the PDF file using PKCS1 object
        pdfSignSingle.sign(doc.getPages().size(), "Document numérisé conforme à l'original", "DSI", "CHU", true, 
            new java.awt.Rectangle(30, 780, 500, 50), new PKCS1(par.repSign + par.certFile, par.certPwd));
        // Set image for signature appearance
        pdfSignSingle.setSignatureAppearance(par.repSign + "cadenat-sign.png");
        // Save final output
        System.out.println("Signature de : " + filename);
        pdfSignSingle.save(filename);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

The error message occurs deep on the Aspose call stack so I don’t really have a way to figure out the issue.

Thanks for your help !

@Pandalex

Could you please share any sample PDF document with which your shared code snippet is failing and giving an exception. We will test the scenario in our environment and address it accordingly. Also, please make sure to test the case with 21.2v of the API before sharing the requested information.