UnifiedHighlighter's re-analysis offset strategies decode every extracted query term as UTF-8, so a binary term (for example a binary StringField id reached with requireFieldMatch=false) makes highlighting throw

Finding LFV-803Area: highlighter / UnifiedHighlighter re-analysis offset strategies (MemoryIndexOffsetStrategy, TokenStreamOffsetStrategy)Priority: mediumImpact: crashNovelty: known upstream

AI-assisted finding, confirmed by automated checks, not yet triaged by a human Lucene committer. This site files nothing upstream.

What it shows

You build UnifiedHighlighter.builder(null, analyzer).withFieldMatcher(f -> true) (the documented requireFieldMatch=false switch) and call highlightWithoutSearcher("body", query, "hello world", 1) with query = SHOULD id:<binary bytes 9F 12 FF 00 41> + SHOULD body:hello, and expect "<b>hello</b> world", because binary terms are documented Lucene input (StringField's BytesRef constructor), the id term can never occur in analyzed text, the byte-based POSTINGS and TERM_VECTORS offset sources do not throw on such a term, and the classic Highlighter and the default field matcher highlight the same query. Instead the call throws: the default MemoryIndexOffsetStrategy passes the raw term bytes to Automata.makeStringUnion, which is documented to take UTF-8 and throws IllegalArgumentException 'Invalid UTF8 header byte: 0x9f', and TokenStreamOffsetStrategy (withPassageRelevancyOverSpeed(false)) calls BytesRef.utf8ToString, which throws AssertionError with -ea and ArrayIndexOutOfBoundsException with -da. The same happens through highlight() on a stored text field without offsets, and on a field with offsets when the query also has a prefix clause on it.

Expected vs actual

Files

Run it

# Lucene checkout at the tested commit, built with: ./gradlew --no-daemon assemble   (JDK 25)
LUCENE=/path/to/lucene; V=12.0.0-SNAPSHOT
CP=$LUCENE/lucene/core/build/libs/lucene-core-$V.jar
CP=$CP:$LUCENE/lucene/codecs/build/libs/lucene-codecs-$V.jar
CP=$CP:$LUCENE/lucene/test-framework/build/libs/lucene-test-framework-$V.jar
CP=$CP:$LUCENE/lucene/highlighter/build/libs/lucene-highlighter-$V.jar
CP=$CP:$LUCENE/lucene/memory/build/libs/lucene-memory-$V.jar
CP=$CP:$LUCENE/lucene/queries/build/libs/lucene-queries-$V.jar
CP=$CP:randomizedtesting-runner-2.9.2.jar:junit-4.13.2.jar:hamcrest-3.0.jar   # test-framework dependencies (Maven Central)
CP=$CP:junit-platform-console-standalone-6.1.3.jar   # JUnit Platform console launcher (Maven Central)

javac -d classes -cp "$CP" $(find src -name '*.java')

# run 1: assertions on, seed DEADBEEF
java -ea -esa --add-modules jdk.incubator.vector --enable-native-access=ALL-UNNAMED -Dtests.seed=DEADBEEF \
     -cp "classes:$CP" org.junit.platform.console.ConsoleLauncher \
     execute --select-class org.apache.lucene.search.uhighlight.TestUnifiedHighlighterBinaryQueryTerm

Gradle alternative: copy the test into the matching module's src/test/ tree of the checkout and run ./gradlew -p lucene/<module> test --tests <class> -Ptests.seed=<seed> (add -Ptests.asserts=false for a run without assertions).

Feedback

Open an issue in lucene-ai-bug-hunt. Please do not open issues or pull requests in apache/lucene about this finding unless a Lucene committer agrees it should be filed.

Snapshot of 2026-11-03. AI-assisted; not yet triaged by a human Lucene committer. Feedback: open an issue in lucene-ai-bug-hunt.