NullPointerException is Thrown when Using addClone Method in Java

I’m experiencing a strange behaviour. On one system (Windows 7), I’m getting a NullPointerException when I try to use the addClone method (as well as in other situations). On the other hand, on a different computer (Windows 10) I don’t get any exception.
I was able to reproduce this behaviour in a minimal program. Consider the class (NB the file empty_presentation.pptx is a file containing a single, empty slide):

import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class AsposeDebugging {
public static void main(String[] args) throws IOException {
File file = new File(“empty_presentation.pptx”);
InputStream stream = new FileInputStream(file);
Presentation template = new Presentation(stream);
ISlide firstSlide = template.getSlides().get_Item(0);
Presentation finalPresentation = new Presentation();
finalPresentation.getSlides().addClone(firstSlide);
System.out.println(“Done!”);
}
}

I used Aspose.Slides creating a maven project with the line

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

and adding to the pom.xml file

     		<repository>
     			<id>AsposeJavaAPI</id>
     			<name>Aspose Java API</name>
     			<url>https://repository.aspose.com/repo/</url>
     		</repository>
     		<dependency>
     			<groupId>com.aspose</groupId>
     			<artifactId>aspose-slides</artifactId>
     			<version>21.1</version>
     			<classifier>jdk16</classifier>
     		</dependency>

(the tags in the quoted text above are garbled by the message forum formatter; sorry but I don’t know how to prevent it)

On one system (Windows 10) the main() method runs correctly, on another system (Windows 7) it crashes with the following strack strace:

    at com.aspose.slides.internal.mv.class.do(Unknown Source)
    at com.aspose.slides.internal.mv.class.new(Unknown Source)
    at com.aspose.slides.internal.mv.class.for(Unknown Source)
    at com.aspose.slides.internal.mv.class.do(Unknown Source)
    at com.aspose.slides.internal.m4.for.do(Unknown Source)
    at com.aspose.slides.internal.fm.this.if(Unknown Source)
    at com.aspose.slides.internal.fm.this.case(Unknown Source)
    at com.aspose.slides.internal.fm.long.do(Unknown Source)
    at com.aspose.slides.internal.fm.long.<init>(Unknown Source)
    at com.aspose.slides.internal.fm.long.<init>(Unknown Source)
    at com.aspose.slides.internal.fm.long.<init>(Unknown Source)
    at com.aspose.slides.internal.oq.public.do(Unknown Source)
    at com.aspose.slides.o4.do(Unknown Source)
    at com.aspose.slides.o4.do(Unknown Source)
    at com.aspose.slides.o4.do(Unknown Source)
    at com.aspose.slides.ano.do(Unknown Source)
    at com.aspose.slides.oi.do(Unknown Source)
    at com.aspose.slides.ln.do(Unknown Source)
    at com.aspose.slides.o0.do(Unknown Source)
    at com.aspose.slides.ape.int(Unknown Source)
    at com.aspose.slides.ape.boolean(Unknown Source)
    at com.aspose.slides.apb.do(Unknown Source)
    at com.aspose.slides.apb.<init>(Unknown Source)
    at com.aspose.slides.TextFrame.do(Unknown Source)
    at com.aspose.slides.TextFrame.do(Unknown Source)
    at com.aspose.slides.TextFrame.void(Unknown Source)
    at com.aspose.slides.r.do(Unknown Source)
    at com.aspose.slides.rd.do(Unknown Source)
    at com.aspose.slides.rd.do(Unknown Source)
    at com.aspose.slides.bg.do(Unknown Source)
    at com.aspose.slides.ak2.do(Unknown Source)
    at com.aspose.slides.agb.do(Unknown Source)
    at com.aspose.slides.af1.do(Unknown Source)
    at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
    at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
    at com.aspose.slides.SlideCollection.addClone(Unknown Source)
    at com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:18)

I tried several versions of Aspose, different pptx files in input and different Java versions, but in all cases on the Windows 7 system I get the exception. Any suggestions?

@LorenzoL,
Welcome to our community! Thank you for the issue description. It will take me some time to investigate the issue. I will notify you a little later. Thank you for your patience.

1 Like

@LorenzoL,
I have logged the issue in our tracking system with ID SLIDESJAVA-38469 for further investigation. You will be notified when it is fixed.

1 Like

@LorenzoL,
We cannot reproduce the issue. Please share additional information:

  • Source presentation (“empty_presentation.pptx”)
  • JDK version (full version number)
  • Windows 7 version (build)

According to StackTrace, the problem occurs when Aspose.Slides tries to read information about a font. Could you also check the font accessibility of fonts and share your ‘windows/fonts’ folder from Windows 7 (as an archive)?

Thanks for looking into this. As I mentioned in my original post, I was also unable to reproduce the problem on other systems.

-Windows 7 Enterprise, Service Pack 1, “currentBuild” 7601 ( value from HKEY_LOCAL_MACHINE>Software>Microsoft>Windows NT>CurrentVersion )

-As far as I can tell I have normal access to c:\Windows\Fonts (I tried copying the folder and I was able to do it without problem). Maybe aspose is trying to access a specific font which is not there…?

@LorenzoL,
Thank you for the additional information. Could you please share your fonts from the Windows\Fonts folder?

The system where I’m having the problem is at work, and I’m not allowed to copy large files from there, I can only send email with small attachments. The Windows\Fonts directory is about 250MB zipped (450 MB unzipped), so I cannot easily copy it from the system. I can ask for a special authorization from the system administrator, if you think it’d necessary. What I can do now it to make a available the list of font files there: Dropbox - File Deleted - Simplify your life
Please let me know if I should go on and ask permission. Is there any way to see what fonts aspose is trying to access?

@LorenzoL,
Thank you for the additional information.

Aspose.Slides usually works with embedded and system fonts. Also, external fonts can be specified to use.
More details: PowerPoint Fonts

@LorenzoL,
Our development team investigated the issue and found no problems. We need fonts from the Windows\Fonts folder from the Windows system in which the problem is reproduced for further investigation.

As an update, I regrettably have to report that the problem never went away for me. I’ve tried my best to find anything unusual in the Windows/Fonts directory but failed. Any hint whatever would be appreciated, because I’m really at the end of my tether with this issue.

@LorenzoL,
This issue has been closed since you have not replied for 3 months. We did our best to help you, but we have not managed to reproduce the error. It would be great if you could share additional information for reproducing the error on our side. Then we could continue.

The information on the system are still the same as I described in my original post… unfortunately I was denied the possibility to share the Windows/Fonts directory (because there are some proprietary fonts there – it’s paranoid but there’s nothing I can do for now…). BTW I noticed that the method FontsLoader.getFontFolders() returns an empty array… could this be the reason of the error?

Update: adding the following two lines before the line with the addClone method

String[] dirs = {“C:\WINDOWS\Fonts”};
FontsLoader.loadExternalFonts(dirs);

changes the error message to (my bold):

Exception in thread “main” class com.aspose.slides.exceptions.ArgumentNullException: Value cannot be null.
Parameter name: path1
com.aspose.slides.internal.fs.catch.if(Unknown Source)
com.aspose.slides.internal.on.double.int(Unknown Source)
com.aspose.slides.internal.on.double.do(Unknown Source)
com.aspose.slides.internal.oq.else.do(Unknown Source)
com.aspose.slides.internal.oq.else.goto(Unknown Source)
com.aspose.slides.internal.oq.else.case(Unknown Source)
com.aspose.slides.internal.oq.case.do(Unknown Source)
com.aspose.slides.o4.do(Unknown Source)
com.aspose.slides.o4.do(Unknown Source)
com.aspose.slides.o4.do(Unknown Source)
com.aspose.slides.oi.do(Unknown Source)
com.aspose.slides.oi.do(Unknown Source)
com.aspose.slides.ln.do(Unknown Source)
com.aspose.slides.o0.do(Unknown Source)
com.aspose.slides.ape.int(Unknown Source)
com.aspose.slides.ape.boolean(Unknown Source)
com.aspose.slides.apb.do(Unknown Source)
com.aspose.slides.apb.(Unknown Source)
com.aspose.slides.TextFrame.do(Unknown Source)
com.aspose.slides.TextFrame.do(Unknown Source)
com.aspose.slides.TextFrame.void(Unknown Source)
com.aspose.slides.r.do(Unknown Source)
com.aspose.slides.rd.do(Unknown Source)
com.aspose.slides.rd.do(Unknown Source)
com.aspose.slides.bg.do(Unknown Source)
com.aspose.slides.ak2.do(Unknown Source)
com.aspose.slides.agb.do(Unknown Source)
com.aspose.slides.af1.do(Unknown Source)
com.aspose.slides.MasterSlideCollection.do(Unknown Source)
com.aspose.slides.MasterSlideCollection.do(Unknown Source)
com.aspose.slides.SlideCollection.addClone(Unknown Source)
com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:39)
at com.aspose.slides.internal.fs.catch.if(Unknown Source)
at com.aspose.slides.internal.on.double.int(Unknown Source)
at com.aspose.slides.internal.on.double.do(Unknown Source)
at com.aspose.slides.internal.oq.else.do(Unknown Source)
at com.aspose.slides.internal.oq.else.goto(Unknown Source)
at com.aspose.slides.internal.oq.else.case(Unknown Source)
at com.aspose.slides.internal.oq.case.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.oi.do(Unknown Source)
at com.aspose.slides.oi.do(Unknown Source)
at com.aspose.slides.ln.do(Unknown Source)
at com.aspose.slides.o0.do(Unknown Source)
at com.aspose.slides.ape.int(Unknown Source)
at com.aspose.slides.ape.boolean(Unknown Source)
at com.aspose.slides.apb.do(Unknown Source)
at com.aspose.slides.apb.(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.void(Unknown Source)
at com.aspose.slides.r.do(Unknown Source)
at com.aspose.slides.rd.do(Unknown Source)
at com.aspose.slides.rd.do(Unknown Source)
at com.aspose.slides.bg.do(Unknown Source)
at com.aspose.slides.ak2.do(Unknown Source)
at com.aspose.slides.agb.do(Unknown Source)
at com.aspose.slides.af1.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.SlideCollection.addClone(Unknown Source)
at com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:39)

Process finished with exit code 1

@LorenzoL,

This usually should not occur. I passed all your additional information to our development team. We will investigate this case further.

1 Like

@LorenzoL,
Unfortunately, our development team still cannot reproduce this issue on our side. But based on investigations of the provided stack traces, our developers found that the issue is related to accessing the fonts folder. The main problem with accessing the fonts folder has been fixed in Aspose.Slides 21.5. Please check the issue with the latest version of Aspose.Slides.

1 Like

Thank you, Andrey. I tried again using versions 2.1, 2.6, 2.7 and 2.8. I can see that the output changed a bit, although it still doesn’t work.
The program I’m using for tests is now as follows:

package com.mycompany.app;

import com.aspose.slides.FontsLoader;
import com.aspose.slides.ISlide;
import com.aspose.slides.ISlideCollection;
import com.aspose.slides.Presentation;

public class AsposeDebugging {
    public static void main(String[] args) {
    String version = com.aspose.slides.License.getVersion();
    System.out.println("Aspose slides version is: " + version);

    Presentation template = new Presentation("empty_presentation.pptx");
    ISlide firstSlide = template.getSlides().get_Item(0);

    Presentation finalPresentation = new Presentation();
    ISlideCollection mySlides = finalPresentation.getSlides();

    System.out.println("FontsLoader.getFontFolders().length = " + FontsLoader.getFontFolders().length);
    for (int i = 0; i < FontsLoader.getFontFolders().length; i++) {
        System.out.println("FontsLoader.getFontFolders()[" + i + "]=" + FontsLoader.getFontFolders()[i]);
    }


    //This line will trigger an exception if the fonts directory is not setup correctly!
    mySlides.addClone(firstSlide);

    System.out.println("Done!");
}

The full outputs are quoted at the end of this message. In short, in version 21.1 I have FontsLoader.getFontFolders().length = 0
In version 21.6 and 21.7
FontsLoader.getFontFolders().length = 1
but the String that should contain the path is empty.
In version 21.8
FontsLoader.getFontFolders().length = 1
and when I try to access FontsLoader.getFontFolders()[0] I get the error
Exception in thread "main" class com.aspose.slides.exceptions.InvalidOperationException: Cannot find any fonts installed on the system.

Output for version 21.1:
Aspose slides version is: 21.1
FontsLoader.getFontFolders().length = 0
Exception in thread “main” java.lang.NullPointerException
at com.aspose.slides.internal.mv.class.do(Unknown Source)
at com.aspose.slides.internal.mv.class.new(Unknown Source)
at com.aspose.slides.internal.mv.class.for(Unknown Source)
at com.aspose.slides.internal.mv.class.do(Unknown Source)
at com.aspose.slides.internal.m4.for.do(Unknown Source)
at com.aspose.slides.internal.fm.this.if(Unknown Source)
at com.aspose.slides.internal.fm.this.case(Unknown Source)
at com.aspose.slides.internal.fm.long.do(Unknown Source)
at com.aspose.slides.internal.fm.long.(Unknown Source)
at com.aspose.slides.internal.fm.long.(Unknown Source)
at com.aspose.slides.internal.fm.long.(Unknown Source)
at com.aspose.slides.internal.oq.public.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.ano.do(Unknown Source)
at com.aspose.slides.oi.do(Unknown Source)
at com.aspose.slides.ln.do(Unknown Source)
at com.aspose.slides.o0.do(Unknown Source)
at com.aspose.slides.ape.int(Unknown Source)
at com.aspose.slides.ape.boolean(Unknown Source)
at com.aspose.slides.apb.do(Unknown Source)
at com.aspose.slides.apb.(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.void(Unknown Source)
at com.aspose.slides.r.do(Unknown Source)
at com.aspose.slides.rd.do(Unknown Source)
at com.aspose.slides.rd.do(Unknown Source)
at com.aspose.slides.bg.do(Unknown Source)
at com.aspose.slides.ak2.do(Unknown Source)
at com.aspose.slides.agb.do(Unknown Source)
at com.aspose.slides.af1.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.SlideCollection.addClone(Unknown Source)
at com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:35)

Output for version 21.6 and 21.7:
Aspose slides version is: 21.7
FontsLoader.getFontFolders().length = 1
FontsLoader.getFontFolders()[0]=
Exception in thread “main” java.lang.NullPointerException
at com.aspose.slides.internal.m9.class.do(Unknown Source)
at com.aspose.slides.internal.m9.class.new(Unknown Source)
at com.aspose.slides.internal.m9.class.for(Unknown Source)
at com.aspose.slides.internal.m9.class.do(Unknown Source)
at com.aspose.slides.internal.ng.for.do(Unknown Source)
at com.aspose.slides.internal.fm.this.if(Unknown Source)
at com.aspose.slides.internal.fm.this.case(Unknown Source)
at com.aspose.slides.internal.fm.long.do(Unknown Source)
at com.aspose.slides.internal.fm.long.(Unknown Source)
at com.aspose.slides.internal.fm.long.(Unknown Source)
at com.aspose.slides.internal.fm.long.(Unknown Source)
at com.aspose.slides.internal.o3.boolean.do(Unknown Source)
at com.aspose.slides.pp.do(Unknown Source)
at com.aspose.slides.pp.do(Unknown Source)
at com.aspose.slides.pp.do(Unknown Source)
at com.aspose.slides.aou.do(Unknown Source)
at com.aspose.slides.o4.do(Unknown Source)
at com.aspose.slides.l8.do(Unknown Source)
at com.aspose.slides.pv.do(Unknown Source)
at com.aspose.slides.aqk.int(Unknown Source)
at com.aspose.slides.aqk.boolean(Unknown Source)
at com.aspose.slides.aqg.do(Unknown Source)
at com.aspose.slides.aqg.(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.void(Unknown Source)
at com.aspose.slides.r.do(Unknown Source)
at com.aspose.slides.ry.do(Unknown Source)
at com.aspose.slides.ry.do(Unknown Source)
at com.aspose.slides.bj.do(Unknown Source)
at com.aspose.slides.alz.do(Unknown Source)
at com.aspose.slides.ag8.do(Unknown Source)
at com.aspose.slides.agw.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.SlideCollection.addClone(Unknown Source)
at com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:35)

Output for version 21.8
Aspose slides version is: 21.8
FontsLoader.getFontFolders().length = 1
FontsLoader.getFontFolders()[0]=
Exception in thread “main” class com.aspose.slides.exceptions.InvalidOperationException: Cannot find any fonts installed on the system.
com.aspose.slides.internal.o8.extends.do(Unknown Source)
com.aspose.slides.pv.do(Unknown Source)
com.aspose.slides.pv.do(Unknown Source)
com.aspose.slides.pv.do(Unknown Source)
com.aspose.slides.apb.do(Unknown Source)
com.aspose.slides.o0.do(Unknown Source)
com.aspose.slides.mc.do(Unknown Source)
com.aspose.slides.p2.do(Unknown Source)
com.aspose.slides.aq2.int(Unknown Source)
com.aspose.slides.aq2.default(Unknown Source)
com.aspose.slides.aqx.do(Unknown Source)
com.aspose.slides.aqx.(Unknown Source)
com.aspose.slides.TextFrame.do(Unknown Source)
com.aspose.slides.TextFrame.do(Unknown Source)
com.aspose.slides.TextFrame.void(Unknown Source)
com.aspose.slides.r.do(Unknown Source)
com.aspose.slides.r6.do(Unknown Source)
com.aspose.slides.r6.do(Unknown Source)
com.aspose.slides.bl.do(Unknown Source)
com.aspose.slides.ame.do(Unknown Source)
com.aspose.slides.ahg.do(Unknown Source)
com.aspose.slides.ag6.do(Unknown Source)
com.aspose.slides.MasterSlideCollection.do(Unknown Source)
com.aspose.slides.MasterSlideCollection.do(Unknown Source)
com.aspose.slides.SlideCollection.addClone(Unknown Source)
com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:35)
at com.aspose.slides.internal.o8.extends.do(Unknown Source)
at com.aspose.slides.pv.do(Unknown Source)
at com.aspose.slides.pv.do(Unknown Source)
at com.aspose.slides.pv.do(Unknown Source)
at com.aspose.slides.apb.do(Unknown Source)
at com.aspose.slides.o0.do(Unknown Source)
at com.aspose.slides.mc.do(Unknown Source)
at com.aspose.slides.p2.do(Unknown Source)
at com.aspose.slides.aq2.int(Unknown Source)
at com.aspose.slides.aq2.default(Unknown Source)
at com.aspose.slides.aqx.do(Unknown Source)
at com.aspose.slides.aqx.(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.do(Unknown Source)
at com.aspose.slides.TextFrame.void(Unknown Source)
at com.aspose.slides.r.do(Unknown Source)
at com.aspose.slides.r6.do(Unknown Source)
at com.aspose.slides.r6.do(Unknown Source)
at com.aspose.slides.bl.do(Unknown Source)
at com.aspose.slides.ame.do(Unknown Source)
at com.aspose.slides.ahg.do(Unknown Source)
at com.aspose.slides.ag6.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.SlideCollection.addClone(Unknown Source)
at com.mycompany.app.AsposeDebugging.main(AsposeDebugging.java:35)

@LorenzoL,
Unfortunately, I still cannot reproduce the exception you described. Please check the accessibility to some font from your application as shown below:

File file = new File("C:Windows/Fonts/ARIALN.TTF");
FileInputStream stream = new FileInputStream(file);
byte[] data = new byte[(int)file.length()];
int read = stream.read(data);
System.out.println(read);
1 Like

Thank you for your answer. I checked the font accessibility by putting the 5 lines of codes in your previous message, checking all font files in a loop (I have 714 font files). I got no errors, all System.out.println(read) lines return an integer.
I got the font filenames by “dir c:\Windows\Fonts” and then hard-coded the list as a String array in the .java file. The test is done in the same Java program which then opens the presentation and eventually raises the exception. So it seems that all fonts can be accessed without problems…

@LorenzoL,
I passed the additional information to our development team. We will investigate this case further and inform you of any progress.

@LorenzoL,
Please perform the next investigations separately.

  1. Copy the fonts from “C:/Windows/Fonts” folder to another folder (“C:/Temp/Fonts” or your project folder, for example). Then load them as external fonts using FontsLoader.loadExternalFonts method. Then execute your code example and share results.

  2. Execute the following code example in your app and share output:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (java.awt.Font font : ge.getAllFonts()) {
    System.out.println(font.getName());
    try {
        Object font2D = null;
        try {
            font2D = Class.forName("sun.font.FontUtilities").getDeclaredMethod("getFont2D", new Class[]{java.awt.Font.class})
                    .invoke(null, new Object[]{font});
        } catch (Throwable ignored) {
            try {
                font2D = Class.forName("sun.font.FontManager").getDeclaredMethod("getFont2D", new Class[]{java.awt.Font.class})
                        .invoke(null, new Object[]{font});
            } catch (Throwable e) {
            }
        }
        java.lang.reflect.Field platNameField = Class.forName("sun.font.PhysicalFont").getDeclaredField("platName");
        platNameField.setAccessible(true);
        if (font2D != null) {
            System.out.println(platNameField.get(font2D));
        }
    } catch (Throwable e) {
    }
}