john-wagster opened a new issue, #16999:
URL: https://github.com/apache/lucene/issues/16999
### Description
Since Lucene 10, constructing a `SimplePatternTokenizer` from a regexp
string fails for many patterns:
```java
new SimplePatternTokenizer("ab|ac");
// java.lang.IllegalArgumentException: please determinize the incoming
automaton first
```
The same call works on Lucene 9.x.
[LUCENE-10010](https://github.com/apache/lucene/commit/b2e866b703) changed
`RegExp#toAutomaton()` to no longer determinize. `SimplePatternSplitTokenizer`
was updated to determinize explicitly:
```java
public SimplePatternSplitTokenizer(AttributeFactory factory, String regexp,
int determinizeWorkLimit) {
this(factory, Operations.determinize(new RegExp(regexp).toAutomaton(),
determinizeWorkLimit));
}
```
but `SimplePatternTokenizer` was not:
```java
public SimplePatternTokenizer(AttributeFactory factory, String regexp, int
determinizeWorkLimit) {
this(factory, new RegExp(regexp).toAutomaton());
}
```
As a result, `determinizeWorkLimit` is silently ignored, and any pattern
that `RegExp` compiles to a non-deterministic automaton (e.g. alternations with
overlapping branches such as `ab|ac` or
`[0-9]{2}/[0-9]{2}/[0-9]{4}|[0-9]{4}-[0-9]{2}-[0-9]{2}`) is rejected by the
tokenizer's own `Automaton` constructor.
`SimplePatternTokenizerFactory` is not affected, since it determinizes
before calling the `Automaton` constructor. The existing tests only use
patterns that already compile to deterministic automata, which is likely why
this wasn't caught.
This surfaced in Elasticsearch 9.x (`simple_pattern` tokenizer), where we
worked around it by determinizing in the Elasticsearch factory:
elastic/elasticsearch#164857, elastic/elasticsearch#164859.
**Proposed fix:** determinize in the `String` constructor using
`determinizeWorkLimit`, mirroring `SimplePatternSplitTokenizer`. Happy to open
a PR.
### Version and environment details
Lucene 10.0.0 and later (reproduced on 10.5.2; the code is unchanged on
`main`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]