Cannot save PSD as PNG using Java (ImageLoadException)

Hi there,

We’re evaluating the Aspose library 21.7 for Java and running into some exceptions.

Warning: the fonts "Times" and "Times" are not available for the Java logical font "Serif", which may have unexpected appearance or behavior. Re-enable the "Times" font to remove this warning.
Warning: the fonts "Times" and "Times" are not available for the Java logical font "Serif", which may have unexpected appearance or behavior. Re-enable the "Times" font to remove this warning.
the fonts "Times" and "Times" are not available for the Java logical font "Serif", which may have unexpected appearance or behavior. Re-enable the "Times" font to remove this warning.

Exception in thread "main" class com.aspose.psd.coreexceptions.ImageLoadException: Image saving failed. ---> java.lang.IllegalAccessError: class com.aspose.psd.internal.jg.j (in unnamed module @0x5bb4f7d1) cannot access class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl (in module java.base) because module java.base does not export sun.reflect.generics.reflectiveObjects to unnamed module @0x5bb4f7d1
   --- End of inner exception stack trace ---
com.aspose.psd.Image.save(Unknown Source)
com.aspose.psd.Image.save(Unknown Source)
Main.main(Main.java:28)
	at com.aspose.psd.Image.save(Unknown Source)
	at com.aspose.psd.Image.save(Unknown Source)
	at Main.main(Main.java:28)
Caused by: java.lang.IllegalAccessError: class com.aspose.psd.internal.jg.j (in unnamed module @0x5bb4f7d1) cannot access class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl (in module java.base) because module java.base does not export sun.reflect.generics.reflectiveObjects to unnamed module @0x5bb4f7d1
	at com.aspose.psd.internal.jg.j.a(Unknown Source)
	at com.aspose.psd.internal.iS.ac.a(Unknown Source)
	at com.aspose.psd.internal.je.f.<init>(Unknown Source)
	at com.aspose.psd.fileformats.psd.layers.TextLayer.getTextData(Unknown Source)
	at com.aspose.psd.internal.jf.l.c(Unknown Source)
	at com.aspose.psd.internal.jf.l.b(Unknown Source)
	at com.aspose.psd.internal.jf.l.a(Unknown Source)
	at com.aspose.psd.internal.iO.d.b(Unknown Source)
	at com.aspose.psd.internal.iO.d.a(Unknown Source)
	at com.aspose.psd.internal.iN.c$d.a(Unknown Source)
	at com.aspose.psd.internal.iN.c$d.process(Unknown Source)
	at com.aspose.psd.internal.iN.c$c.a(Unknown Source)
	at com.aspose.psd.internal.gL.bc.a(Unknown Source)
	at com.aspose.psd.internal.gL.bc.a(Unknown Source)
	at com.aspose.psd.internal.gL.bc.a(Unknown Source)
	at com.aspose.psd.internal.gL.bc.a(Unknown Source)
	at com.aspose.psd.internal.iN.c$b.loadPartialArgb32Pixels(Unknown Source)
	at com.aspose.psd.internal.gL.ba.a(Unknown Source)
	at com.aspose.psd.internal.gL.bc.a(Unknown Source)
	at com.aspose.psd.internal.gL.bc.a(Unknown Source)
Caused by: java.lang.IllegalAccessError: class com.aspose.psd.internal.jg.j (in unnamed module @0x5bb4f7d1) cannot access class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl (in module java.base) because module java.base does not export sun.reflect.generics.reflectiveObjects to unnamed module @0x5bb4f7d1

This is when saving a PSD file as PNG using this code:

    // Fix Aspose exception for locale
    Locale.setDefault(new Locale("en-us"));

    // Set licence
    var licence = new License();
    licence.setLicense(Main.class.getClassLoader().getResourceAsStream("Aspose.PSD.Java.lic"));

    // Load PSD
    var psd = Image.load(Main.class.getClassLoader().getResourceAsStream("psd-demo.psd"));

    // Prepare output
    var outFilePath = System.getProperty("user.dir") + "/aspose-evaluation/output/";
    var resultFilePath = outFilePath + "out1.png";
    var pngOptions = new PngOptions();
    pngOptions.setColorType(PngColorType.TruecolorWithAlpha);

    // Save PNG
    psd.save(resultFilePath, pngOptions);

The PSD image I want to use has 10 layers; 4 image layers (1 hidden), 5 text layers and 1 Shape layer. Another PSD image that can be used to reproduce is this one: https://customerscanvas.com/help/designers-manual/adobe/photoshop/files/text.psd

Does anyone here have an idea of how to resolve this?

Please try to fix it with the following arguments:
–add-opens=java.base/java.util.regex=ALL-UNNAMED
–add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED

Also, it can be fixed with the downgrading of Java Version.

1 Like

Thank you!

Still didn’t work unfortunately when using these flags.

Just for me to understand, which Java version should be downgraded to? I tried OpenJDK Runtime Environment Corretto-16.0.2.7.1 (build 16.0.2+7)

Downgrading Aspose PSD to version 20.5 from 21.7 has resolved the issue. Possibly there is a bug here @DmitriySorokin .

@janjouketjalsmatrivago please also check the following topic: Java version support

1 Like

I created additional investigation task PSDJAVA-414: Exception on load: Module java.base does not export sun.reflect.generics.reflectiveObjects to unnamed module. When it’ll be resolved you’ll get the notification.

1 Like