Draft
Conversation
Generate changelog in
|
schlosna
reviewed
Aug 14, 2025
| import java.util.function.BiConsumer; | ||
| import java.util.function.Supplier; | ||
|
|
||
| public final class ScopedValues { |
There was a problem hiding this comment.
worth linking https://openjdk.org/jeps/506
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.
This adds support for runtime access to
java.lang.ScopedValuewithout requiring preview features to be enabled, and without requiring a move to JDK25 language level, in a manner similar to virtual thread support in this library.Note that ScopedValue is a preview feature in JDK21+, which would typically require compiling and running with
--enable-preview. However, since we use reflection here, this check appears to be bypassed at runtime, so as long as we are running on JDK21 the classes should be available at runtime (though internal implementations and even the APIs may have changed since JDK21).The use case for this is to allow consumers who either: (a) are running on Java 21 thru Java 24 to be able to use ScopedValue without explicitly requiring
--enable-preview; or (b) are (or will be) running on Java 25 but targeting bytecode versions earlier than that.I'm not sure that nylon-threads is the best place to house this code, as ScopedValue doesn't directly relate to the other code here, so happy to move this elsewhere if it makes more sense (though it is relevant to virtual threads in general as a more performant way to supply thread-local variables).
TODOs: