Repository navigation
Add unit tests for BitTricks.isAsciiOnly - #706
Merged
Ladicek merged 1 commit intoAug 24, 2026
Merged
Conversation
BitTricks.isAsciiOnly had no direct tests, despite having two implementations that must be kept in sync (the byte loop in src/main/java and the VarHandle variant in src/main/java11) and being on the ASCII fast path of UTF-8 index serialization. These tests pin the base implementation's contract across the empty input, single-byte high-bit and boundary values (0x7F and 0x80), non-ASCII bytes in short inputs, and window/offset handling. Input lengths are chosen around the eight-byte batch boundary (0, 1, 7, 8, 11, 16) so the same cases also cover the java11 variant's batch and tail paths if that variant is ever placed on the test classpath. Signed-off-by: Tiziano Basile <[email protected]>
Ladicek
approved these changes
Aug 24, 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.
BitTricks.isAsciiOnly had no direct tests, even though it sits on the ASCII fast path used when writing UTF-8 strings during index serialization, and it has two implementations that must be kept in sync: the plain byte loop in src/main/java and the VarHandle variant in src/main/java11 that reads eight bytes at a time followed by a byte-by-byte tail.
This PR adds a BitTricksTest that pins the contract: empty input, single-byte high-bit and boundary values (0x7F must pass, 0x80 and 0xFF must fail), non-ASCII bytes in short inputs, and that bytes outside the [off, off+len) window are ignored. It also poisons every byte position across two full batches so each lane and the batch seam are covered. The input lengths (0, 1, 7, 8, 11, 16) are chosen around the eight-byte batch boundary so the same cases exercise the java11 variant's batch and tail paths as well.
The test lives in package org.jboss.jandex because both the class and the method are package-private; all existing tests are in org.jboss.jandex.test, so this introduces the first same-package test. Happy to move it or take a different approach if you would rather keep tests out of the production package.
One thing worth flagging: a normal mvn test runs against the base byte-loop implementation only. The java11 VarHandle variant is layered into the multi-release JAR at package time, after the test phase, so it is not on the test classpath and these tests do not actually execute it. The class comment says as much. Genuinely exercising the java11 variant (and adding a differential test that compares it against the base loop, which would be the real guard against the two drifting) needs some surefire or multi-release test wiring. I left that out to keep this change small, but I am happy to follow up with it if you are interested.
Verified locally with mvn -pl core test -Dtest=BitTricksTest on JDK 21: 15 tests, all passing.