Skip to content

OPENNLP-1955: Reject surrogate separators in StringUtil.split and check it against String.split - #1305

Merged
rzo1 merged 1 commit into
apache:mainfrom
ai-pipestream:OPENNLP-1955-split-followup
Sep 17, 2026
Merged

rzo1 merged 1 commit into
apache:mainfrom
ai-pipestream:OPENNLP-1955-split-followup

Conversation

@krickert

Copy link
Copy Markdown
Contributor

Follow-up to #1302, based on main. The review of that PR landed after the merge, so its one commit is here.

  • StringUtil.split: a surrogate char as separator let the char scan split a supplementary code point between its two chars, while String.split with the same one-char pattern matches code points and keeps the pair intact. Both overloads now throw IllegalArgumentException for a surrogate separator. Javadoc and @throws say so, and four tests cover the high and low surrogate bounds.
  • StringUtilSplitTest: a seeded differential test compares both overloads with String.split on the quoted separator over 20,000 random inputs built from 12 separators (including # $ . |), ASCII and supplementary code points, and the limits 0, 1, 2, 3, 5, 7 and -1. The equivalence claim of OPENNLP-1955: Replace literal String.split calls with a regex-free StringUtil.split #1302 is now checked in CI rather than in a commit message.
  • FineGrainedReportListener: the six category sites did contains("-") and then indexOf('-'), two scans per label inside comparators. One indexOf each now.

opennlp-api 426 and opennlp-cli 38 tests with checkstyle and forbiddenapis, -Dopennlp.forkCount=1. No manual change and no eval build: the parsers produce the same fields.

OPENNLP-1955

@mawiesne
mawiesne requested a review from rzo1 September 16, 2026 05:56
@mawiesne mawiesne added java Pull requests that update Java code tests Pull requests that add or update test code labels Sep 16, 2026
….split in the test, single scan in the report listener

A surrogate char as separator would let the character scan split a
supplementary code point between its two chars, where String.split with the same
one-char pattern matches code points and keeps the pair intact. Both
overloads now throw IllegalArgumentException for a surrogate separator,
with the Javadoc stating the rule, and four pinning tests cover the
high and low surrogate bounds.

StringUtilSplitTest adds a seeded differential test: 20,000 random
inputs built from separators, ASCII and supplementary code points,
12 separators including the metacharacters hash, dollar, dot and
pipe, and limits 0, 1, 2, 3, 5, 7 and -1, each compared with
String.split on the quoted separator for both overloads.

FineGrainedReportListener finds the category dash with one indexOf per
label instead of contains followed by indexOf, at the six sites the
earlier commit changed.

opennlp-api: 426 tests, opennlp-cli: 38 tests, checkstyle clean.
(cherry picked from commit bececbfd9aae87cc1fb3a5d47efa45da3cc57348)
@krickert
krickert force-pushed the OPENNLP-1955-split-followup branch from 219750b to 39c1c07 Compare September 16, 2026 06:09
@rzo1
rzo1 merged commit dff5e5d into apache:main Sep 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code tests Pull requests that add or update test code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants