KB Article #189280

Runtime error due to missing add-opens or add-exports

Problem

Since 5.5-20241219 ST Uses Java 21 which enforces a strong encapsulation policy rather than a relaxed encapsulation policy. This translates to forbidding access of code to private classes, methods and fields outside of the given Java module.

It is possible that some third party libraries depending on reflection to access private classes, methods and fields to cause a RuntimeException of the form:

<code>Exception in thread "main" java.lang.IllegalAccessError: class Test
  (in unnamed module @0x5e481248) cannot access class
  sun.security.util.SecurityConstants (in module java.base) because
  module java.base does not export sun.security.util to unnamed
  module @0x5e481248</code>

or

<code>Exception in thread "main" java.lang.reflect.InaccessibleObjectException:
  Unable to make field private java.security.KeyStoreSpi
  java.security.KeyStore.keyStoreSpi accessible: module java.base does
  not "opens java.security" to unnamed module @6e2c634b </code>

Resolution

Add an --add-opens or --add-exports for the required package in [STInstallDir]/bin/common.sh and [STInstallDir]/bin/utils/common.sh. Example:

JAVA_OPTS="--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED $JAVA_OPTS"

JAVA_OPTS="--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED $JAVA_OPTS"