NullpointerException in PresentationEx p = new PresentationEx(inputStream)

Hello,

I am getting a NullpointerException when trying to create a new PresentationEx instance.

MyClass.java:


String fileName = “/pptx_empty.pptx”;
URL resourceUrl = getClass().getResource(fileName);
try {
Path resourcePath = Paths.get(resourceUrl.toURI());
resourcePath.getFileName();
File file = resourcePath.toFile();
FileInputStream in = new FileInputStream(file);
PresentationEx presentation = new PresentationEx(in);

The Exception:

java.lang.NullPointerException
at com.aspose.slides.pf4dd765c.pbdb106a0.pa5e0ff62.ad.do(Unknown Source)
at com.aspose.slides.pf4dd765c.pbdb106a0.p2cbca448.b.do(Unknown Source)
at com.aspose.slides.PatternFormatEx.do(Unknown Source)
at com.aspose.slides.PatternFormatEx.(Unknown Source)
at com.aspose.slides.LineFillFormatEx.(Unknown Source)
at com.aspose.slides.LineFormatEx.(Unknown Source)
at com.aspose.slides.PortionFormatEx.(Unknown Source)
at com.aspose.slides.PortionFormatEx.(Unknown Source)
at com.aspose.slides.ParagraphFormatEx.(Unknown Source)
at com.aspose.slides.PresentationEx.(Unknown Source)
at domain.myplugin.example.MyClass.createPresentationFromFile(MyClass.java:100)


The input stream is not null, I checked in debug mode. Also the NullPointerException should be caught by the framework.

Environment:
**********
I am using Atlassian Confluence 5.1.5 and develop a plugin for it to import ppt and pptx files. So far I managed to import ppt-files using the “Presentation” class. But trying to do the same for pptx-files using the “PresentationEx” class leads to the error described above. For testing purposes I wrote a unit test and noticed that I was able to create a “PresentationEx” just fine outside Confluence. So maybe it has something to do with OSGI bundles. I am running out of options though, and would really appreciate it, if you could tell me what the obfuscated code is doing.

Questions:
********
1. What is the obfuscated code trying to do? Can you show me the source code for that part?

Hi Stefan,

Thanks for sharing the details with us. I have created an issue with ID SLIDESJAVA-34179 in our issue tracking system to further investigate and resolve the issue of NullPointer exception when loading Aspose.Slides in Atlassian Confluence environment for PPTX. I have also observe the similar inquiry from you in another forum thread mentioned here:
https://forum.aspose.com/t/classnotfoundexception-when-calling-com-aspose-slides-slide-getthumbnail-method/68961
where by you have shared the same issue. You have shared that for PPT you have been able to resolve the issue but for PPTX you are getting NullPointer Exception. We will invesgtigate the issue on our end to help you further and will share the feedback with you as soon as it will be shared by our development team.

We are sorry for your inconvenience,

Hi Stefan,

I like to share that similar issue has been reported by another customer where by he was getting the same exception while accessing Aspose.Slides in OSGI Bundle application. We found the problem in java.lang.Thread.currentThread().getContextClassLoader() which return ‘null’ if called within an OSGi bundle.

The client made a “mistake” in openPresentation() method.

Actual Sample Code:

public String openPresentation()
{
String returnMessage;

PresentationEx presentation = null;
try
{
InputStream stream = new FileInputStream(“Test.pptx”);
presentation = new PresentationEx(stream);
returnMessage = “Presentation Opened Successfuly”;
}
catch(Exception x)
{
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter, true);
x.printStackTrace(printWriter);
returnMessage = "Error opening presentation: " + stringWriter.getBuffer().toString();
}
return returnMessage;
}


Modified Sample code:

public String openPresentation() {
String returnMessage;

PresentationEx presentation = null;
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
try {
InputStream stream = new FileInputStream(“d://Aspose Data///Test.pptx”);

presentation = new PresentationEx(stream);
returnMessage = “Presentation Opened Successfuly”;
} catch(Exception x) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter, true);
x.printStackTrace(printWriter);
returnMessage = "Error opening presentation: " + stringWriter.getBuffer().toString();
}
}
finally
{
Thread.currentThread().setContextClassLoader(tccl);
}
return returnMessage;
}

Can you please observe the suggested changes and try similar implementation on your end. I am hopeful things will work. If there is still an issue then please provide us a sample OSGI eclipse project that is reproducing the issue on your end. I will try to help you further by investigating further on my end.

Many Thanks,