GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fill every remaining byte in the Java 8 SplittableRandom.nextBytes fallback by Marti2203 · Pull Request #18009 · netty/netty

Conversation

@Marti2203

@Marti2203 Marti2203 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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.

The new test fails without the change (length 2 ==> array contents differ at index [1], expected: <-77> but was: <0>) and passes with it; PlatformDependentTest passes.

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
@Marti2203
Fill every remaining byte in the Java 8 SplittableRandom.nextBytes fa…
898ed78
…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 normanmaurer added this to the 4.2.20.Final milestone Oct 22, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Oct 22, 2026
normanmaurer
normanmaurer approved these changes Oct 22, 2026
View reviewed changes
@testlens-app

testlens-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 898ed78
▶️ Tests: 54198 executed
⚪️ Checks: 30/30 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer merged commit 14d1d84 into netty:4.2 Oct 22, 2026
31 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot netty-project-bot mentioned this pull request Oct 22, 2026
Auto-port 5.0: Fill every remaining byte in the Java 8 SplittableRandom.nextBytes fallback #18030
Merged
@netty-project-bot

netty-project-bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #18030

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Oct 22, 2026
normanmaurer pushed a commit that referenced this pull request Oct 22, 2026
@netty-project-bot @Marti2203
Auto-port 5.0: Fill every remaining byte in the Java 8 SplittableRand…
50a64d0
…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]>
@netty-project-bot

netty-project-bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest chrisvest removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Oct 22, 2026
@chrisvest

chrisvest commented Oct 22, 2026

Copy link
Copy Markdown
Member

We don't have this code in 4.1 so no backport needed.

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

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.20.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Marti2203 @netty-project-bot @chrisvest @normanmaurer
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.