After switching to POI 5.1.0, XSLFSlide.importContent throw an NPE if source slide contain an image. Exception in thread "main" java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Objects.java:221) at org.apache.commons.io.input.UnsynchronizedByteArrayInputStream.<init>(UnsynchronizedByteArrayInputStream.java:68) at org.apache.poi.openxml4j.util.ZipArchiveFakeEntry.getInputStream(ZipArchiveFakeEntry.java:92) at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.getInputStream(ZipInputStreamZipEntrySource.java:112) at org.apache.poi.openxml4j.opc.ZipPackagePart.getInputStreamImpl(ZipPackagePart.java:106) at org.apache.poi.openxml4j.opc.PackagePart.getInputStream(PackagePart.java:504) at org.apache.poi.xslf.usermodel.XSLFPictureData.getInputStream(XSLFPictureData.java:77) at org.apache.poi.xslf.usermodel.XSLFPictureData.getData(XSLFPictureData.java:89) at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:664) at org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:414) at org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:455) at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:434) at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:293) at Main.main(Main.java:14) Working fine on 5.0.0. Steps to reproduce : - Create a slide with one image with powerpoint - Load it with new XMLSlideShow(inputStream) - Import the first slide into a new XMLSlideShow() - NPE occurs I have created a sample project to demontrate the bug : https://github.com/Halvra/poi-import-slide-with-image Tell me if you need more details.
So the issue is that you close the SlideShow in getTemplate. POI 5.1.0 uses the close method to decide it is time to free up resources associated with the SlideShow object instance. The NullPointerException is caused by the data byte array that backs the image data having been set to null as part of the SlideShow close. Can you change your getTemplate to return the slideshow (and leave it open)? You can close the input stream. You should close the template SlideShow after you have finished using it - eg after you import the content of the slide into the new slideshow.
I added r1894830 and r1894831 and will look at extending tests later
Ok, thanks for the fast response and the details. I refactored my code and it's work fine now ! :) The RuntimeException with detailed error message is a good idea for avoiding the same issue should be reported.