Repository navigation
OPENNLP-1935: Regex removal (10/10): Forbid java.util.regex in production code - #1348
Conversation
ec0968c to
f152df5
Compare
|
Rebased main, updated description. AI assisted summary (reviewed and edited).
|
|
Jumped the gun on making this green - after 547 is done, this will be green. |
Is this blocked by #1236? |
|
@jzonthemtn yup.. I can make it 10/10 a draft for now. It needs 547 (and it's ticket stack I'd rebase right after that would help 547 - it's made to be stacked w/it)... So order would be: #1236 |
Also - NBD but there's still about 30 or so places to clean up in the codebase for the regex stuff - not needed for the 3.0 release (the surface was a lot bigger than I thought). It's just something we should just chip away at. The ones we have here are the hot path for most. The other tickets expose some minor API changes made to remove Pattern from constructors. |
|
@jzonthemtn going to put this in draft temporarily - #1360 has a nit where we would need to add to this list after it merges too. To minimize churn, I'll keep this in draft until #1236 and #1360 both complete. |
f152df5 to
12f23a1
Compare
12f23a1 to
7cde11f
Compare
7cde11f to
f80870a
Compare
…napis Add a forbiddenapis check for production classes in every module. Reject java.util.regex and regex-based String and Scanner methods at process-classes, before tests run. Exclude test classes and point error messages to the StringUtil replacements. Add SuppressForbidden for documented APIs that accept user-supplied regular expressions. Require a reason for each exception and apply it to RegexNameFinder and RegexNameFinderFactory. Document the rule, dev/forbidden-regex.txt and allowed exceptions in CONTRIBUTING.md. The build will fail until the remaining production regex uses are removed by the related PRs. Assisted-by: Claude Code 2.1.281 Co-authored-by: Kristian Rickert <kristian@apache.org> Co-authored-by: Claude <noreply@anthropic.com> Reviewed-by: Kristian Rickert <kristian@apache.org> Signed-off-by: Kristian Rickert <kristian@apache.org>
EventFields, MascIdentifiers, MecabDictionary and HunspellDictionary each had the same split loop with a different character test. StringUtil has it as one private loop behind splitNonEmpty, splitOnUnicodeWhitespace and the new mode-aware splitOnWhitespace, and the four classes call those.
… tags Mark the tokenizer alphanumeric-pattern API and the AnCora head-rule tag matching with @SuppressForbidden, since both regular expressions are public, user-supplied contracts.
33f013b to
af2de34
Compare
|
lgtm. Think it is a major step forward. Thx @krickert and team. |
|
Thank you! I've also identified the remaining regex brats, we're down to about 3ish PRs for us to be regex free :) I have branches for these, but still cleaning to draft them into PR |
Part 10 of the regex removal series, kept as a draft until the remaining classes are converted. Continues #1282 on an apache branch.
A forbiddenapis execution checks the production classes of every module against
dev/forbidden-regex.txt:java.util.regex,String.split,String.matches,String.replaceAll,String.replaceFirstandScanner.useDelimiter. It runs atprocess-classes, before the tests, and its message names theStringUtilreplacements. Tests are not checked, so test code can keep using regular expressions.Exceptions: a member with a documented public contract that is a user-supplied regular expression is marked with
@SuppressForbidden(reason). OnlyRegexNameFinderandRegexNameFinderFactoryhave it. A private pattern is converted, not annotated, so the report of the check is the to-fix list for the rest of the series.CONTRIBUTING.mdhas the rule.Also in this PR:
StringUtilhas one non-empty split loop behindsplitNonEmpty,splitOnUnicodeWhitespaceand the mode-awaresplitOnWhitespace, replacing the copies inEventFields,MascIdentifiers,MecabDictionaryandHunspellDictionary.Report on main today: 104 findings in 13 classes. The tokenizer factories and
TokenizerME, the parser family,NameSample,FeatureGeneratorUtil,SpellCheckingCharSequenceNormalizer, and the rest ofConlluStream,DownloadUtilandTokenSampleStreamis #1280.OPENNLP-1935