All analysis factory constructors fail if the passed in map is immutable [LUCENE-6655]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
One of our tests tried to initialise a StandardTokenizer by passing a version into the factory. Unfortunately, this required passing a map:
```Java
return new StandardTokenizerFactory(ImmutableMap.of(
AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM,
Version.LUCENE_4_6_1.toString()
)).create();
```
This then fails:
```
java.lang.UnsupportedOperationException
at com.google.common.collect.ImmutableMap.remove(ImmutableMap.java:338)
at org.apache.lucene.analysis.util.AbstractAnalysisFactory.get(AbstractAnalysisFactory.java:122)
at org.apache.lucene.analysis.util.AbstractAnalysisFactory.(AbstractAnalysisFactory.java:71)
at org.apache.lucene.analysis.util.TokenizerFactory.(TokenizerFactory.java:70)
at org.apache.lucene.analysis.standard.StandardTokenizerFactory.(StandardTokenizerFactory.java:42)
```
I suspect that someone put in a `remove` when it should have been a `get`... bit of a weird mistake to make, especially when you don't know whether the map will permit it.
I haven't verified whether the same occurs in later versions but getting updated to 5.2.1 will probably be the next thing on my list.
---
Migrated from [LUCENE-6655](https://issues.apache.org/jira/browse/LUCENE-6655) by Trejkaz, 1 vote
Contributor guide
Research direction
Start with org.apache.lucene.analysis.util.AbstractAnalysisFactory and trace the constructor path shown through TokenizerFactory and StandardTokenizerFactory. Reproduce the failure using the immutable map from the report, then verify that the analysis factory constructors accept it without UnsupportedOperationException and add or update a focused regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100