TIFF to PDF NullReferenceException

Dear all

We are using the latest Aspose imaging package for Java (23.3).
In our usecase we convert multiple tiff to pdf and under Load with multiple threads we have some sporadic Exception:

Caused by: com.aspose.imaging.coreexceptions.ImageSaveException: Image export failed. at com.aspose.imaging.Image.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.RasterImage.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.q.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.ql.b.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.ql.c.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.Image.save(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.company.documents.office.service.converter.Image2PDF.tiffFrameToPdfImage(Image2PDF.java:81) ~[classes/:na] at com.company.documents.office.service.converter.Image2PDF.convertTiffImage(Image2PDF.java:70) ~[classes/:na] at com.company.documents.office.service.converter.Image2PDF.convert(Image2PDF.java:53) ~[classes/:na] at com.company.documents.office.service.OfficeFile2PDFService.lambda$convertFileToPdf$1(OfficeFile2PDFService.java:75) ~[classes/:na] ... 107 common frames omitted Caused by: com.aspose.imaging.internal.Exceptions.NullReferenceException: Object reference not set to an instance of an object. at com.aspose.imaging.internal.li.aD.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.hm.f.loadPartialArgb32Pixels(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.aI.bx.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.aI.bA.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.aI.bA.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.aI.bA.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.aI.aT.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.RasterImage.b(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.RasterImage.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.fileformats.tiff.TiffFrame.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.bc.Q.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.bc.L.a(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.bc.y.b(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] at com.aspose.imaging.internal.bc.y.export(Unknown Source) ~[aspose-imaging-23.3-jdk16.jar:23.3] ... 117 common frames omitted

If the same tiff is converted again, we usually do not see the exception again.

@stud0r, please provide for us code to reproduce and set of images to reproduce on. Thanks.

I cannot provide you the image, as it is sporadic and it does not happen reproducibly by the image, but reproducibly by the high load.

Please find attached the code:

private void convertTiffImage(TiffImage tiffImage, OutputStream pdfStream) {
    try (Document pdf = new Document()) {
        for (TiffFrame frame : tiffImage.getFrames()) {
            com.aspose.pdf.Image pdfImage = tiffFrameToPdfImage(frame);
            addImageToPdfPage(pdf, pdfImage, frame);
        }
        pdf.convert(new PdfFormatConversionOptions(PdfFormat.PDF_A_1B));
        pdf.save(pdfStream);
    }
}

private com.aspose.pdf.Image tiffFrameToPdfImage(TiffFrame frame) {
    com.aspose.pdf.Image pdfImage = new com.aspose.pdf.Image();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    frame.save(stream, frame.getFrameOptions());
    // set blackAndWhite manually, there is no automatic detection
    pdfImage.setBlackWhite(frame.getBitsPerPixel() == 1);
    pdfImage.setImageStream(new ByteArrayInputStream(stream.toByteArray()));
    return pdfImage;
}

private Page addImageToPdfPage(Document document, com.aspose.pdf.Image image, TiffFrame frame) {
    Page page = document.getPages().add();
    page.getPageInfo().setWidth(frame.getWidth());
    page.getPageInfo().setHeight(frame.getHeight());
    page.getParagraphs().add(image);
    return page;
}

@stud0r, we will try to reproduce your issue and will notify as will be ready to answer issue.

Hello, @stud0r
We can not reproduce this bug but we localized the place where it appears and made changes in the code for avoiding this situation. This change (#IMAGINGJAVA-8419 task) will be a part of the next release of Aspose.Imaging for Java 23.4

Hi @evgeniy.sidenko
Thank you for the promissing feedback. When is the release of Aspose.Imaging for Java 23.4 planed?

ETA May 15 2023