Repository navigation
Access Unsafe only on demand, and better protect against unavailability - #97
Merged
Merged
Conversation
Marcono1234
force-pushed
the
lazy-load-unsafe
branch
2 times, most recently
from
November 24, 2026 19:49
906293b to
9892027
Compare
Marcono1234
force-pushed
the
lazy-load-unsafe
branch
from
November 24, 2026 19:53
9892027 to
2493768
Compare
Marcono1234
commented
Nov 24, 2026
Contributor
Author
There was a problem hiding this comment.
Have updated this to match the code changes. I don't use Claude currently, so I don't know if this change is useful.
Member
There was a problem hiding this comment.
Thanks! I'll have a look -- I do use Claude.
Contributor
Author
|
I hope this PR will help in case Please let me know what you think about this PR and if you want anything changed. |
Marcono1234
marked this pull request as ready for review
November 24, 2026 19:56
- `UnsafeChunkDecoder`/`UnsafeChunkEncoder` constructors now throw a clear `IllegalStateException` when `Unsafe` is unavailable, instead of failing on first use (encoder checks before the base constructor takes recycled buffers) - `UnsafeAccess.isUnsafeSupported()` catches `Throwable` so "optimal" factories always fall back to the Vanilla codecs - Keep `ChunkDecoderFactory` constructor private (no new public API) - Make `UnsafeAccess` final with a private constructor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New `UnsafeDeniedTest`, run with `--sun-misc-unsafe-memory-access=deny` by an extra surefire execution in a `jdk24+` profile (auto-activated on JDK 24+); checks factories fall back to Vanilla, direct Unsafe codec construction fails fast, and block/streaming round trips still work - `UnsafeAccessTest` no longer fails when `Unsafe` is denied - Drop explicit JDK API javadoc link (redirect is an error on JDK 25 javadoc); the plugin's default `detectJavaApiLink` links it offline - Add JDK 25 to the CI build matrix Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cowtowncoder
approved these changes
Nov 30, 2026
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 tries to address the two problems mentioned in #86 (comment):
ChunkEncoderFactory#optimal...methods only catchExceptionIf in future JDK versions
Unsafemethods are indeed removed, most likely aLinkageError(or subclass) would occur, which is anError, not anException.ChunkDecoderFactorystaticblock currently unconditionally tries to initializeUnsafeChunkDecoderThis leads to "A terminally deprecated method in sun.misc.Unsafe has been called" warnings (see also JEP 498), even if the user only uses 'safe' decoder methods, because
UnsafeChunkDecoderduring class initialization accessesUnsafemethods.This PR tries to solve this by moving the direct
Unsafeaccess to a newUnsafeAccessclass and adding aisUnsafeSupported()method. This should hopefully:Avoid any direct
Unsafeaccess merely whenUnsafeChunkDecoderorUnsafeChunkEncoderare initializedAvoiding access to
Unsafeif the user only uses the 'safe' APINote: It seems there might unfortunately be some parts of the API where the user cannot chose between 'safe' and 'optimal' (possibly
Unsafe-based), so in these cases the user can likely not avoid the "terminally deprecated method ... called" warnings.