v00d00c0de opened a new issue, #11989:
URL: https://github.com/apache/lucene/issues/11989
### Description
_org.apache.lucene.analysis.pattern.PatternReplaceFilter_ supports null
value in 'replacement' parameter which is eventually replaced by an empty
string.
After an upgrade of OpenSearch from 1.2.3 to 2.4.0:
Creating _PatternReplaceFilter_ via _PatternReplaceFilterFactory_ and
passing a Map which contains 'replacement' entry with a null value causes NPE.
```
Caused by: java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:221)
at
java.base/java.util.ImmutableCollections$MapN.<init>(ImmutableCollections.java:797)
at java.base/java.util.Map.ofEntries(Map.java:1620)
at java.base/java.util.Map.copyOf(Map.java:1684)
at
org.apache.lucene.analysis.AbstractAnalysisFactory.<init>(AbstractAnalysisFactory.java:95)
at
org.apache.lucene.analysis.TokenFilterFactory.<init>(TokenFilterFactory.java:95)
at
org.apache.lucene.analysis.pattern.PatternReplaceFilterFactory.<init>(PatternReplaceFilterFactory.java:52)
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at
org.apache.lucene.analysis.AnalysisSPILoader.newFactoryClassInstance(AnalysisSPILoader.java:195)
at
org.apache.lucene.analysis.AnalysisSPILoader.newInstance(AnalysisSPILoader.java:141)
at
org.apache.lucene.analysis.TokenFilterFactory.forName(TokenFilterFactory.java:52)
at
org.apache.lucene.analysis.custom.CustomAnalyzer$Builder.addTokenFilter(CustomAnalyzer.java:392)
... 68 more
```
As can be seen, _java.util.Map.copyOf(...)_ does not allow nulls as keys or
values of the given map.
To reproduce:
Use
_org.apache.lucene.analysis.custom.CustomAnalyzer.Builder.addTokenFilter(String,
Map<String, String>)_ with the following parameters:
"patternReplace", {pattern=SOME_PATTERN, replace=all, replacement=null}
### Version and environment details
Lucene 9.4.1 (OpenSearch 2.4.0)
Java 11
Windows 10
--
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]