NullPointer exception is throwing during cloning shapes (C# .NET)

Hi,


we are upgrading from Aspose
Slides 7.9.0 to version
14.6.0.

We are generating PPTs from Template Files in a servlet of a web application. After adapting the code to the new version we get a null pointer exception when cloning shapes. We were able to isolate the problem in a few lines of code.

Running as standalone app (as shown below) that works fine. As soon as we execute that code in a servlet we get a NullPointerException at the red line (destSlide and sourceShape are valid, though).

public class PowerPoint {
public static void main(String[]
args) {
Presentation srcPres = new Presentation(“test.ppt”);
Presentation destPres = new Presentation();
ISlide
sourceSlide = srcPres.getSlides().get_Item(0);
ISlide
destSlide = destPres.getSlides().get_Item(0);
for (IShape
sourceShape : sourceSlide.getShapes()) {
IShape destShape = destSlide.getShapes().addClone(sourceShape);
destShape.setY(destShape.getY() + destShape.getHeight());
}
destPres.save(“test1.ppt”, SaveFormat.Ppt);
}
}

Do you have any suggestions how to solve the problem?

Thanks,
Manfred

Hi Manfred,


I have observed your code and it seems okay. Please share the sample presentation so that I may investigate the issue on my end but before that I suggest you to please try Aspose.Slides for Java 15.2.0 on your end first.

Best Regards,

Hi Adnan,



I upgraded to Aspose.Slides 15.2.0 but that didn’t help.



The PPT I used for the test case is quite simple: a single slide with a single AutoShape. I’ll attach it anyhow.



The null pointer error can only be observed, when the code is run in a servlet context of our application. Obviously there is an interference with some of the other libraries we are using. In the debugger I can see, that it takes several seconds to process the addClone call before the NullPointerException is thrown. Obviously there happens some recursion which uses up Memory.



I found this error message in the log during startuop of our Tomcat:



Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/PPR] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [com.aspose.p2cbca448.ay->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object]



I’ve already tried to increase the stack size (-Xss) but to no avail.



Can you make anything out of this?



Best regards,

Manfred

This is the complete error stack for the NullPointerException:

java.lang.NullPointerException
at com.aspose.slides.p2cbca448.bln.new(Unknown Source)
at com.aspose.slides.aiy.do(Unknown Source)
at com.aspose.slides.aiq.do(Unknown Source)
at com.aspose.slides.bgb.do(Unknown Source)
at com.aspose.slides.bm.do(Unknown Source)
at com.aspose.slides.wl.do(Unknown Source)
at com.aspose.slides.aqs.do(Unknown Source)
at com.aspose.slides.ShapeCollection.addClone(Unknown Source)

Hi Manfred,


I have observed the comments shared by you and it seems that there is some issue while referencing Aspose.Slides for Java in your application or there may be some interference with our jar in your application. In a simple console application there is no issue while cloning the shape from your presentation. I request you to please create a sample servelet based application that is only using Aspose.Slides for Java and no other external API with a chance of interference. Please make sure that API is properly referenced in your sample application. If things work in this scenario then it can be narrowed down if some other API is causing interference on your end. Please share your feedback in this regard so that we may help you further in this regard.

Many Thanks,

Was there ever a solution found for this? I’m seeing the same NPE when either:

  • saving a presentation
  • cloning a slide

It happens with a 4 line project example - writing to binary output stream - and doesn’t have any lib dependencies.

There was a solution, however, I can’t remember what it was. Maybe it was just a coding error (in that case it’s most likely I forgot what the reasons was).

If you get a NPE with just 4 lines of code it’s probably a coding error, too. Maybe there’s missing some intialization. If you share your code with this forum there’s probably someone who can help.

@thebitmuncher,

Can you please share the source application along with Operating system, Java and application details. Please also first try using latest Aspose.Slides for Java 19.3 on your end as well first.

Hi yes - here is the application source - it’s only two lines of code.

I run it like this:

java -cp aspose-slides-19.3-jdk16.jar;. RealSimple

I’m using windows 10 and java 1.8.0_202 - and aspose 19.3

import java.io.ByteArrayOutputStream;

import com.aspose.slides.Presentation;

public class RealSimple {

	public static void main(String[] args) {

		Presentation pres = new Presentation();	

		pres.save(new ByteArrayOutputStream(), com.aspose.slides.SaveFormat.Pptx); // fails NPE		
	}
}

@thebitmuncher,

I have worked with sample code shared by you using Aspose.Slides for Java 19.3 along with java 1.8.0_212, windows 10 environment and unable to observe issue. Can you please try to use latest java version on your end.