Skip to content

OPENNLP-1898: Address the OPENNLP-1876 review follow-ups - #1196

Merged
rzo1 merged 1 commit into
mainfrom
OPENNLP-1898
Jul 28, 2026
Merged

OPENNLP-1898: Address the OPENNLP-1876 review follow-ups#1196
rzo1 merged 1 commit into
mainfrom
OPENNLP-1898

Conversation

@krickert

Copy link
Copy Markdown
Contributor

Completes the review of OPENNLP-1876 (#1151). These notes were raised in that review and
addressed on 2026-07-16, but the commit was never pushed and #1151 merged later the same
day without it, so the work is missing from main.

No behaviour changes. This is review follow-up work: 6 files, 68 insertions, 41 deletions.

What this adds

Undocumented exceptions on public spellcheck API.
SpellCheckingCharSequenceNormalizer.normalize throws IllegalArgumentException on a
null input and IllegalStateException when no SpellChecker is attached, and two setters
reject out of range values. None of that was declared. The @throws tags are added so the
contract is visible to callers, matching the rest of the normalizer family.

Lost explanation on SpellCorrectingTokenStream.
The class javadoc no longer explained that the stream is token count preserving in
contrast to SpellCorrectingObjectStream in compound mode, which is the property callers
rely on to keep tags and spans aligned with corrected tokens. That contrast and the cross
reference are restored.

Reference patterns recompiled on a hot path.
The Number, Shrink, SocialMedia and Url characterization tests each called
Pattern.compile inside the test body for the former regexes they differentially test
against. Those are the randomized tests that run 5000 generated inputs per case, so the
patterns were recompiled per invocation. They are hoisted into named static final
constants (FORMER_DIGIT_REGEX, FORMER_SPACE_REGEX, FORMER_REPEATED_CHAR_REGEX,
FORMER_HASH_USER_REGEX, FORMER_RT_REGEX, FORMER_FACE_REGEX, FORMER_URL_REGEX,
FORMER_MAIL_REGEX), which also names what each pattern is instead of leaving a bare
literal inside the assertion.

The adversarial URL test hid which input failed.
weirdUrlsMatchTheFormerRegexExactly drove a hard coded String[] of adversarial URL
shapes (userinfo, ports, percent escapes, IPv6 brackets, backslashes, IDN and punycode
hosts) through one @Test, so a regression reported only that the test failed. It is now
a @ParameterizedTest with @MethodSource, so the failing shape is named in the report.

Verification

Branch is based on current main (a8642301f) and applies cleanly.

  • ./mvnw -pl opennlp-extensions/opennlp-spellcheck,opennlp-core/opennlp-runtime -am test-compile succeeds
  • characterization suite: 55 tests, 0 failures, 0 errors, including
    SocialMediaCharSequenceNormalizerCharacterizationTest (9) and
    UrlCharSequenceNormalizerCharacterizationTest (32)

These notes were raised in the review of OPENNLP-1876 and addressed before
PR #1151 merged, but the commit was never pushed, so the work is absent
from main.

- Document IllegalArgumentException and IllegalStateException on the public
  spellcheck normalizer, which throws both but declared neither
- Restore the SpellCorrectingTokenStream class javadoc, including the
  contrast with SpellCorrectingObjectStream in compound mode that explains
  why the stream is token count preserving
- Hoist the former-regex Pattern constants out of the four characterization
  test bodies, where they were recompiled on every one of the 5000
  randomized inputs per case, and name what each pattern represents
- Turn the adversarial URL pins into a parameterized test so a regression
  names the shape that broke instead of only the test
@rzo1
rzo1 merged commit 71e1fd9 into main Jul 28, 2026
7 checks passed
@rzo1
rzo1 deleted the OPENNLP-1898 branch July 28, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants