IBM Support

java.util.MissingResourceException may occur when using java.util.ResourceBundle.getBundle() in RPG and Java

Troubleshooting


Problem

A java.util.MissingResourceException may occur when calling the java.util.ResourceBundle.getBundle() Java method as an external procedure from RPG.  Even though the resource bundle directory is included in the value of the CLASSPATH environment variable or -classpath/-cp Java options, the resource bundle name still cannot be found.
 
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name <bundleName>, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1599)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1415)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:793)

Symptom

Testing showed this issue only occurs when using RPG to execute the java.util.ResourceBundle.getBundle() Java method as an external procedure.
This exception will not occur when the java.util.ResourceBundle.getBundle() Java method is executed in a standalone Java program in Qshell or PASE.

Cause

Changes were introduced to the IBM Developer Kit for Java v8.0 at SR5 FP10 to resolve an Oracle Security fix, "loading of classes from untrusted locations (CVE-2018-2602)".  The IBM APAR IJ04045 for this CVE fix is http://www-01.ibm.com/support/docview.wss?uid=swg1IJ04045 .

Environment

IBM i OS; RPG; Java

Diagnosing The Problem

Example RPG code:  If executed, a "java.util.MissingResourceException: Can't find bundle for base name config.Database, locale en_US" error will be thrown.

CLASSPATH=/MyResourceBundles
config.Database is located in /MyResourceBundles
 
H DftActGrp(*No) ActGrp(*Caller)
D rbClass     C      'java.util.ResourceBundle'
D stringClass C      'java.lang.String'
D resourceB   s     O Class(*JAVA:rbClass)
// ResourceBundle.loadProperties() -- find and load prop file
D loadProperties PR O EXTPROC(*JAVA:rbClass:
D                             'getBundle')
D                             Class(*JAVA:rbClass)
D                             STATIC
D keyName           O Class(*JAVA:stringClass) Const
DString$new   PR    O EXTPROC(*JAVA:
D                     stringClass:
D                     *CONSTRUCTOR)
D value     65535A    VARYING Const
/free
// Try config.Database monitor;
resourceB =loadProperties(String$new('config.Database'));
IF resourceB <> *NULL;
dsply ('config.Database.properties loaded');
ELSE;
dsply ('config.Database.properties null');
ENDIF;
on-error;
dsply ('error getting config.Database');
endmon;
*INLR = *On;
/END-FREE

Resolving The Problem

Execute the following CL command at the beginning of your RPG program to append the bundle directory to the JVM's Bootstrap class loader.  The Bootstrap class loader is at the top of the class loader heirarchy.  By appending the bundle directory's IFS path to the Bootstrap's class loader value, this will allow the JVM to successfully locate and load the resource bundle.
 
ADDENVVAR ENVVAR(IBM_JAVA_OPTIONS) VALUE('-Xbootclasspath/a:/bunderDir') REPLACE(*YES)
where /bundleDir is the IFS directory containing the resource bundle being loaded.
 
If the resource bundle (i.e. config.Database) being loaded is located in the directory /MyResourceBundles, you would need to execute the following CL command at the beginning of the RPG program before Java is invoked and before the JVM is created.  This will append the /MyResourceBundles directory to the JVM's Bootstrap classpath when the JVM is created and allow the resource bundle to be loaded successfully.
 
ADDENVVAR ENVVAR(IBM_JAVA_OPTIONS) VALUE('-Xbootclasspath/a:/MyResourceBundles') REPLACE(*YES)

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CH5AAM","label":"Java Development Kit"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Document Information

Modified date:
20 November 2024

UID

ibm10795838