-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document IAE for Unsafe offset methods #25945
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back liach! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
* @throws NullPointerException if the field is {@code null} | ||
* @throws IllegalArgumentException if the field is static |
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 these checks could be done in Java like:
// implicit null check:
if ((f.getModifiers() & ACC_STATIC) != 0) {
throw new IllegalArgumentException("Field is static");
}
and for the staticField(Offset/Base)
methods:
// implicit null check:
if ((f.getModifiers() & ACC_STATIC) == 0) {
throw new IllegalArgumentException("Field is not static");
}
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.
Don't think anyone is willing to change code here...
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.
That said, the only places that depend on this IAE behavior is the AtomicXxxFieldUpdater classes. All other sites pass trusted fields into these methods, of course besides the sun.misc.Unsafe users which definitely need this IAE. Still I personally prefer adding these checks to atomic field updaters instead of here to reduce risky dependencies.
I noticed that the native implementation of jdk/src/hotspot/share/prims/unsafe.cpp Lines 587 to 594 in 1ca008f
|
Unsafe throws IAE for misusing static vs instance fields, and it's revealed that AtomicXxxFieldUpdaters are using this mechanism to reject static fields. This is not a good practice, but we can at least document this so we don't accidentally introduce problems.
Progress
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25945/head:pull/25945
$ git checkout pull/25945
Update a local copy of the PR:
$ git checkout pull/25945
$ git pull https://git.openjdk.org/jdk.git pull/25945/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25945
View PR using the GUI difftool:
$ git pr show -t 25945
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25945.diff