Bug 65673 - XSLFSlide.importContent throw an NPE when source slide contain an image (since 5.1.0)
Summary: XSLFSlide.importContent throw an NPE when source slide contain an image (sinc...
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 regression (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2021-11-08 09:43 UTC by Julien LEBOUTEILLER
Modified: 2021-11-08 18:04 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Julien LEBOUTEILLER 2021-11-08 09:43:27 UTC
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.
Comment 1 PJ Fanning 2021-11-08 11:11:29 UTC
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.
Comment 2 PJ Fanning 2021-11-08 12:12:35 UTC
I added r1894830 and r1894831 and will look at extending tests later
Comment 3 Julien LEBOUTEILLER 2021-11-08 18:04:05 UTC
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.