Replace usage of SecurityManager and AccessController#doPrivileged#1638
Merged
matthiasblaesing merged 1 commit intoMay 11, 2026
Merged
Conversation
2277556 to
69955bd
Compare
f6b09c3 to
9b5e1ad
Compare
dbwiddis
approved these changes
May 9, 2026
Contributor
dbwiddis
left a comment
There was a problem hiding this comment.
Dug into this and compared to other implementations. LGTM. Only thing I'd add is comments explaining some choices.
| stackWalkerFilterBuilder = new java.util.function.Function<Stream<Object>, Class<?>>() { | ||
| @Override | ||
| public Class<?> apply(Stream<Object> t) { | ||
| Object stackFrame = t.skip(2).findFirst().get(); |
Contributor
There was a problem hiding this comment.
This works but probably deserves a comment on why 2 (vs. old [3]). I'm wondering if there's a better approach by looking for the first stack frame that's outside of c.s.j.Native.
| -------- | ||
| * [#1671](https://github.com/java-native-access/jna/pull/1671): Add `isRISCV` to `c.s.j.Platform` - [@Glavo](https://github.com/Glavo). | ||
| * [#1672](https://github.com/java-native-access/jna/pull/1672): Add `CFLocale`, `CFLocaleCopyCurrent`, `CFCFDateFormatter`, `CFDateFormatterStyle`, `CFDateFormatterCreate` and `CFDateFormatterGetFormat` to `c.s.j.p.mac.CoreFoundation` - [@dbwiddis](https://github.com/dbwiddis). | ||
| * [#1636](https://github.com/java-native-access/jna/issues/1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@matthiasblaesing](https://github.com/matthiasblaesing). |
9b5e1ad to
e2c1f02
Compare
Member
Author
|
@dbwiddis thanks - I added some words about the logic. Does it make sense to you? |
Contributor
Looks great! For clarity, I did compare the JDK9+ implementation vs. other known good fixes for this. The StackWalker was new to me but looks sane and your new comment makes it very clear! |
The SecurityManager class is deprecated for removal since JDK 17. Its getClassContext method is used to optain the calling class when Native#register and Native#unregister are used without the target class being passed in. With JDK 9 the StalkWalker was introduced to make that information available. This change makes both methods available using method handles and prefers the StalkWalker codepath as that is the path expected to be invoked in most cases (on JDK 9+). The AccessController#doProvileged call is replaced by a method handle, assuming, that in an environment where WebStart is available, AccessController is also available. Closes: java-native-access#1636
e2c1f02 to
f5f17d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SecurityManager class is deprecated for removal since JDK 17. Its getClassContext method is used to optain the calling class when Native#register and Native#unregister are used without the target class being passed in. With JDK 9 the StalkWalker was introduced to make that information available. This change makes both methods available using method handles and prefers the StalkWalker codepath as that is the path expected to be invoked in most cases (on JDK 9+).
The AccessController#doProvileged call is replaced by a method handle, assuming, that in an environment where WebStart is available, AccessController is also available.
Closes: #1636