Random shared by threads in RandomIndexWriter and MockAnalyzer [LUCENE-3991]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
This is currently patched by creating a non-asserting Random like this:
```Java
public MockIndexWriter(Random r, Directory dir, IndexWriterConfig conf) throws IOException {
super(dir, conf);
// TODO: this should be solved in a different way; Random should not be shared (!).
this.r = new Random(r.nextLong());
}
```
and
```Java
public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, boolean lowerCase, CharacterRunAutomaton filter, boolean enablePositionIncrements) {
super(new PerFieldReuseStrategy());
// TODO: this should be solved in a different way; Random should not be shared (!).
this.random = new Random(random.nextLong());
```
If you replace new Random(...) with a simple assignment you'll get errors indicating the Random instance is shared (or passed between threads). I don't know how to fix it so I left it as it was before.
---
Migrated from [LUCENE-3991](https://issues.apache.org/jira/browse/LUCENE-3991) by Dawid Weiss (@dweiss)
Contributor guide
Research direction
Start by tracing RandomIndexWriter and MockAnalyzer, including the constructors shown in the issue, to identify how their Random instances are used across threads. Confirm the failure when the instances are shared, then define a thread-safe ownership strategy and verify that the relevant randomized tests no longer report shared Random usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100