Fix Unsafe string paths when -XX:-CompactStrings is used#1
Merged
Conversation
Detect at class init whether JDK compact strings are enabled by checking the internal byte[] length of a known ASCII string. Guard all Unsafe string fast paths (writeString, writeRawString, readString) with this flag so they fall back to safe standard library methods when compact strings are disabled and the internal representation is UTF-16. Add a surefire execution that re-runs all tests with -XX:-CompactStrings.
1 task
lhotari
approved these changes
Mar 17, 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.
Summary
writeString,writeRawString,readString) so they fall back to safe standard library methods when compact strings are disabled (-XX:-CompactStrings)-XX:-CompactStringsto prevent regressionsContext
Reported by @lhotari in apache/pulsar#25332 — the optimized String handling assumes compact strings (LATIN1 coder) are always enabled, which breaks when
-XX:-CompactStringsis used and the internalString.valuebyte array uses UTF-16 encoding.Test plan
-XX:-CompactStrings