IllegalAccessException trying to load a ResourceBundle in 9u181

Vitaly Davidovich vitalyd at
Tue Feb 13 13:03:15 UTC 2018

Hi Mandy,

Thanks very much for your response.  Some comments inline ...

On Mon, Feb 12, 2018 at 7:44 PM, mandy chung <mandy.chung at> wrote:

> On 2/12/18 12:36 PM, Vitaly Davidovich wrote:
> Hi all,
> I'm not sure if core-libs is the right mailing list for jigsaw/modules
> questions these days (rather than jigsaw-dev), so please feel free to
> forward this there if it's the more appropriate list.
> cc'ing  jigsaw-dev
> I have the following code carried over from java 8 (actually much earlier
> than that, but that's beside the point):
> final Resource rb =
> ResourceBundle.getBundle("");
> Resource bundle follows the same encapsulation rule as described in
> Module::getResourceAsStream [1] except that a resource bundle is considered
> as a resource regardless of its format.
Good to know - thanks.

> ResourceBundle.getBundle(String baseName) finds the specified resource
> bundle from the caller's module.  It will first search the resource bundle
> local in the caller's module (via Module::getResourceAsStream) and then
> using the caller's class loader to search for the resource (via
> ClassLoader::getResourceAsStream).   Since the caller is unnamed module
> in your case, for it to access "",
> java.base/ has to be open unconditionally and there is no
> CLI option to do that.

> If you call ResourceBundle.getBundle("",
> Object.class.getModule()) specifying the module of the resource bundle,
> then you can break the encapsulation by `--add-opens
> java.base/`
So I tried calling getBundle(..., Object.class.getModule()), and that
worked - great.  Interestingly, I didn't have to add-opens (or add-export
for that matter).  Is that expected?

> I'm a bit surprised that you depend on JDK internal resource bundle.  Can
> you help us understand why you use it?
Sigh.  Yes, this is an ugly wart in the system, with lots of historical
baggage.  The (really) short of it is we have a custom implementation, which loads this
ResourceBundle (into a static final field).  This is something that's being
addressed in parallel, but I'm trying to make some progress with migrating
the codebase to Java 9 in the meantime.

I should also mention that the real problem I'm troubleshooting is a
NoClassDefFoundError when this custom LoginModule is loaded.  After some
class load/resolution tracing, it appears to me that the impl is found but
fails to initialize properly due to the ResourceBundle static field
initialization.  That's what started me down a path of trying to minimize
the code and seeing what the issue is.

It's also worth mentioning that I'm trying to run the real code on the
9u181 JVM but with code compiled on Java 8 (we have a bunch of compile-time
issues to resolve so wanted to see if we can at least make progress on
running on a 9 JVM).  I would like to try patching this custom login module
to use the new getBundle() overload that takes a Module, but I guess I'll
need to compile it with a java 9 javac.  So yeah, it's ugly unfortunately.

Anyway, thanks for the help - I will try a few more things on my end.  If
you have any suggestions to deal with this frankenstein setup I described
above, I'm all ears.

> Mandy
> [1]
> ResourceBundle.html#getBundle(java.lang.String,java.util.
> Locale,java.lang.Module)

More information about the core-libs-dev mailing list