On Wed, 2 Mar 2022 18:56:40 GMT, Tim Prinzing <d...@openjdk.java.net> wrote:
> The caller class returned by Reflection::getCallerClass was used to gain > access to it's module in most cases and class loader in one case. I added a > method to translate the caller class to caller module so that the decision of > what module represents the caller with no stack frame is made in a single > place. Calls made to caller.getModule() were replaced with > getCallerModule(caller) which returns the system class loader unnamed module > if the caller is null. > > The one place a class loader was produced from the caller in getBundleImpl it > was rewritten to route through the getCallerModule method: > > final ClassLoader loader = (caller != null) ? > caller.getClassLoader() : getLoader(getCallerModule(caller)); > > A JNI test was added which calls getBundle to fetch a test bundle from a > location added to the classpath, fetches a string out of the bundle and > verifies it, and calls clearCache. > > The javadoc was updated for the caller sensitive methods changed. Instead of sprinkling the null caller text in the javadoc in each `getBundle` method, we can specify that that in the class specification, for example, after the "Resource bundles in other modules and class path" section. In cases where the {@code getBundle} factory method is called from a context where there is no caller frame on the stack (e.g. when called directly from a JNI attached thread), the caller module is default to the unnamed module for the {@linkplain ClassLoader#getSystemClassLoader system class loader}. What do you think? src/java.base/share/classes/java/util/ResourceBundle.java line 1588: > 1586: Control control) { > 1587: final ClassLoader loader = (caller != null) ? > 1588: caller.getClassLoader() : > getLoader(getCallerModule(caller)); Suggestion: ClassLoader loader = getLoader(getCallerModule(caller)); This can be simplified as above. I would drop `final` too as it only adds noise to the code. ------------- PR: https://git.openjdk.java.net/jdk/pull/7663