QueryNodeImpl is too mutable [LUCENE-5676]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
We use query nodes both during parsing and as a method of building queries. Somehow a bug has crept into our system where a QueryNode somehow gets mutated to have a parent when the node we created didn't originally have a parent. Some processor in our pipeline treats nodes differently based on the parent, which makes it a very hard to find bug.
It would be very helpful if there were a method like freeze() which would make the instance immutable from thereon, something like the following:
```Java
private volatile boolean frozen;
public final boolean isFrozen() {
return frozen;
};
protected void aboutToMakeChanges() {
if (isFrozen()) {
throw new IllegalStateException("This object is frozen");
}
}
public A freeze() {
frozen = true;
return this;
}
// ...
private void setParent(QueryNode parent) {
aboutToMakeChanges();
// existing code
}
```
---
Migrated from [LUCENE-5676](https://issues.apache.org/jira/browse/LUCENE-5676) by Trejkaz
Contributor guide
Research direction
Start by tracing QueryNodeImpl and the query-node processing pipeline, focusing on how parent relationships are assigned during parsing and query construction. Determine the scope of the proposed freeze behavior and how callers should use it; done means frozen nodes cannot be mutated and the parent-related regression is covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100