GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — Fill every remaining byte in the Java 8 SplittableRandom.nextBytes fallback by Marti2203 · Pull Request #18009 · netty/netty Conversation
Contributor
Motivation: On Java versions before 10, Modification:
Result: The fallback fills every byte and produces the same bytes as The new test fails without the change ( This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…llback Motivation: On Java versions before 10, PlatformDependent.splittableRandomNextBytes fills the array itself. The loop for the bytes after the last full 8-byte block increments i both in its body (data[i++]) and in its update, so every other remaining byte is skipped and stays 0. For a length of 7, bytes 1, 3 and 5 are never written. On Java 10 and later SplittableRandom.nextBytes is used and every byte is filled. Modifications: - Increment i only in the loop update. - Move the fallback into a package-private method so it can be tested on any Java version, and add a test that compares it with the layout of SplittableRandom.nextBytes for lengths 0 to 64. Result: The fallback fills every byte, and produces the same bytes as SplittableRandom.nextBytes for the same seed.
normanmaurer
approved these changes
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
normanmaurer
pushed a commit
that referenced
this pull request
…om.nextBytes fallback (#18030) Auto-port of #18009 to 5.0 Cherry-picked commit: 14d1d84 --- Motivation: On Java versions before 10, `PlatformDependent.splittableRandomNextBytes(SplittableRandom, byte[])` fills the array itself instead of calling `SplittableRandom.nextBytes`. The loop for the bytes after the last full 8-byte block increments `i` both in its body (`data[i++] = ...`) and in its update, so every other remaining byte is skipped and stays `0`. For a 7-byte array, bytes 1, 3 and 5 are never written; for any length that is not a multiple of 8, up to 3 bytes stay zero. On Java 10+ `SplittableRandom.nextBytes` is used and every byte is filled, so the two paths disagree for the same seed. Modification: - Increment `i` only in the loop update. - Move the fallback into a package-private `splittableRandomNextBytesFallback` so it can be tested on any Java version, and add `PlatformDependentTest.testSplittableRandomNextBytesFallbackFillsEveryByte`, which compares it with the layout of `SplittableRandom.nextBytes` (one `nextLong()` per 8 bytes, low byte first, one more for the rest) for lengths 0 to 64. Result: The fallback fills every byte and produces the same bytes as `SplittableRandom.nextBytes` for the same seed. In the netty repository the method is used to generate random payloads in tests and the testsuite, which on Java 8 had zero bytes in their tails. Co-authored-by: Martin Mirchev <[email protected]>
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. | ||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |