-
Notifications
You must be signed in to change notification settings - Fork 6.2k
JDK-8280902 ResourceBundle::getBundle may throw NPE when invoked by JNI code with no caller frame #7663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…NI code with no caller frame
boot class loader.
|
👋 Welcome back tprinzing! A progress list of the required criteria for merging this PR into |
|
@tprinzing The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
naotoj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I believe a CSR is needed for this change.
|
/csr |
|
@tprinzing This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 3 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@naotoj, @mlchung, @magicus) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
@naotoj has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
mlchung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
mlchung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update.
| * stack frame the caller will be null, so the system class loader unnamed | ||
| * module will be used. | ||
| * @param caller | ||
| * @return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you intended to make this /* .... */ instead of javadoc? no need to have @param and @return for this simple method.
| @CallerSensitive | ||
| public static final void clearCache() { | ||
| Class<?> caller = Reflection.getCallerClass(); | ||
| final Module callerModule = getCallerModule(Reflection.getCallerClass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: final can be dropped here.
| #include <stdlib.h> | ||
|
|
||
| #include "jni.h" | ||
| #undef NDEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line unintended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forcing the assert() seems like a good idea in a test
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Properties; | ||
| import java.util.ResourceBundle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: good to keep the imports in alphabetic order.
| } | ||
|
|
||
|
|
||
| private static void makePropertiesFile() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed?
| final String vmDir = Platform.jvmLibDir().toString(); | ||
|
|
||
| // set up shared library path | ||
| final String sharedLibraryPathEnvName = Platform.sharedLibraryPathVariableName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: final adds noise but no other value to the test. Can consider dropping it.
| private static Module getCallerModule(Class<?> caller) { | ||
| Module callerModule = (caller != null) ? caller.getModule() | ||
| : ClassLoader.getSystemClassLoader().getUnnamedModule(); | ||
| return callerModule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: callerModule variable is not needed. It can simply do:
return (caller != null) ? caller.getModule()
: ClassLoader.getSystemClassLoader().getUnnamedModule();
magicus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build changes look good. Can't say anything about the rest.
|
/integrate |
|
@tprinzing |
|
/sponsor |
|
Going to push as commit 31ad80a.
Your commit was automatically rebased without conflicts. |
|
@mlchung @tprinzing Pushed as commit 31ad80a. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
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:
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.
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7663/head:pull/7663$ git checkout pull/7663Update a local copy of the PR:
$ git checkout pull/7663$ git pull https://git.openjdk.java.net/jdk pull/7663/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7663View PR using the GUI difftool:
$ git pr show -t 7663Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7663.diff