apache / apache/lucene

CompiledAutomaton not equal when NFARunAutomaton is non-null

Open
#13,715 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

NFARunAutomaton is does not override `equals`, so defaults to object identity, which means that classes like `CompiledAutomaton` that created internal instances of it may not appear equal when they in fact are. This issue has been filed to investigate the possibility of adding a NFARunAutomaton::equals override that does something sensible with its internal state.

I ran into this issue when comparing this like with Lucene 10:

```
var ca1 = new CompiledAutomaton(automaton, false, true, false);
var ca2 = new CompiledAutomaton(automaton, false, true, false);
assertEquals(ca1, ca2); // <<<< ca1 and ca2 are not equal
```

```
var q1 = new IntervalQuery("f", Intervals.regexp(new BytesRef(".*foo")));
var q2 = new IntervalQuery("f", Intervals.regexp(new BytesRef(".*foo")));
assertEquals(q1, q2); // <<<< q1 and q2 are not equal
...
Expected :org.apache.lucene.queries.intervals.IntervalQuery
Actual :org.apache.lucene.queries.intervals.IntervalQuery

```

Contributor guide

Open the contributing guide

Research direction

Start by reading NFARunAutomaton and the equality paths used by CompiledAutomaton and IntervalQuery. Reproduce the two equality examples from the issue, then inspect the internal state that should determine NFARunAutomaton equality. Done means the reported equivalent objects compare equal without breaking related equality behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.