Alternative to document.isLicensed() in Aspose.PDF for Java (latest version) - so I don't get eval stamps?

I was using document.isLicensed() after setting license when using Java 11. the reason is that if there was some problem setting the license or it expired then I really DO NOT want the eval mode stamps put on my production documents. I would rather log the issue and have the entire process error out.
Any options for me?

under java 21 isLicensed fails
I get an exception on calling pdfDocument.isLicensed()

failed to access class com.aspose.pdf.ADocument from class lucee.invoc.wrap.v4.com.aspose.pdf.ADocument.isLicensed (com.aspose.pdf.ADocument is in unnamed module of loader lucee.commons.lang.PhysicalClassLoader @212577f8; lucee.invoc.wrap.v4.com.aspose.pdf.ADocument.isLicensed is in unnamed module of loader lucee.transformer.dynamic.DynamicClassLoader @495fd9a1);java.lang.IllegalAccessError: failed to access class com.aspose.pdf.ADocument from class lucee.invoc.wrap.v4.com.aspose.pdf.ADocument.isLicensed (com.aspose.pdf.ADocument is in unnamed module of loader lucee.commons.lang.PhysicalClassLoader @212577f8; lucee.invoc.wrap.v4.com.aspose.pdf.ADocument.isLicensed is in unnamed module of loader lucee.transformer.dynamic.DynamicClassLoader @495fd9a1)

apparently - the error “unnamed module of loader lucee.commons.lang.PhysicalClassLoader failed to access class” is a java.lang.IllegalAccessError or java.lang.ClassCastException related to the Java Platform Module System (JPMS), which was introduced in Java 9 and strictly enforced in later versions (Java 16+). This typically occurs when code in an “unnamed module” (code on the traditional classpath, like your Lucee application) attempts to access classes in a named Java module that does not explicitly export those packages for use by unnamed modules.

@larbster

Summary
Calling PdfDocument.isLicensed() can throw an IllegalAccessError on Java 21 because the Aspose PDF for Java JAR is loaded in an unnamed module that does not have access to the internal com.aspose.pdf.ADocument class. The error prevents the usual license‑check call and can cause the library to fall back to evaluation mode, which adds watermarks.

Why it happens

  • Since Java 9 the Java Platform Module System (JPMS) restricts access to classes that are not explicitly exported. In Java 21 the enforcement is stricter, so a call from an unnamed module (e.g., a Lucee application) to the internal ADocument class results in java.lang.IllegalAccessError.
  • Because the license‑check method cannot be executed, the library cannot confirm that a valid license is present and therefore applies the evaluation watermark.

What to do next

  1. Validate the license with the License class
try {
com.aspose.pdf.License lic = new com.aspose.pdf.License();
// load the license file (adjust the path or use an InputStream as needed)
lic.setLicense("Aspose.Pdf.Java.lic");

// Perform a minimal operation that requires a licensed context
new com.aspose.pdf.Document(); // creates an empty PDF document
} catch (Exception e) {
// If any exception is thrown, treat it as a licensing problem
System.err.println("Aspose PDF license validation failed: " + e.getMessage());
throw new RuntimeException("License validation failed", e);
}

Explanation: Loading the license and creating a Document forces the library to evaluate the license early. If the license file is missing, unreadable, or invalid, an exception will be raised and you can abort the process before any PDF is generated.

  1. Check library compatibility with Java 21
  • Verify that you are using a recent Aspose PDF for Java build that officially supports Java 21. Older versions may not include the necessary module descriptors, leading to the IllegalAccessError.
  • If you are on an older version, upgrade to the latest release provided by Aspose.
  1. Adjust class‑loading / module access (temporary workaround)
  • Ensure the Aspose PDF JAR is placed on the classpath rather than the module path in your Lucee deployment.
  • As a short‑term measure, you can open the internal package to unnamed modules with a JVM argument such as:
--add-opens com.aspose.pdf/com.aspose.pdf=ALL-UNNAMED

This tells the JPMS to allow reflective access from unnamed modules. Use this only while you arrange an upgrade to a Java‑21‑compatible version.

  1. Confirm the license file is reachable
  • Verify the file path, class‑path location, and file permissions so the application can read the license.
  • If you load the license from an InputStream, make sure the stream remains open until setLicense completes.
  1. Integrate a fail‑fast check into your workflow
  • Run the validation code (step 1) at application start‑up or before any PDF generation job.
  • If the validation throws, log the error and abort the job to guarantee that no document is produced with evaluation watermarks.

By loading the license explicitly with com.aspose.pdf.License, performing a minimal licensed operation, and ensuring you are on a Java 21‑compatible Aspose PDF version (or using the JPMS --add-opens flag temporarily), you can detect licensing problems early and prevent unwanted evaluation stamps.

Note: The exact behaviour of License.setLicense and the need for module‑opening flags may vary between Aspose releases. Test the approach with your specific version and environment.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

I am using the latest version of aspose PDF which is java 21 compatible.
When I try your suggestion - Perform a minimal operation that requires a licensed context - the operation does not kick out an exception, it just writes an eval stamp to the pages, so I am not convinced that approach will work.

I tried adding the JVM arg
–add-opens com.aspose.pdf/com.aspose.pdf=ALL-UNNAMED
but tomcat would not start with that in place.

Currently my only option is to disable the license checks - as that bombs out my process. This is a risky scenario as there is potentially a lot of cleanup work if the library slips into an eval state by accident.

Any more ideas?
thanks!!

@larbster

If possible, could you please share a simple application in .zip format so that we can use it replicate the issue in our environment and address it accordingly?