# Custom TokenFilter Plugin Class Initialization and Parameter Validation

**URL:** <https://discuss.elastic.co/t/custom-tokenfilter-plugin-class-initialization-and-parameter-validation/79472>\
**Category:** Elasticsearch\
**Created:** [March 21, 2017, 4:43pm UTC](https://discuss.elastic.co/t/custom-tokenfilter-plugin-class-initialization-and-parameter-validation/79472 "2017-03-21T16:43:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [March 21, 2017, 4:43pm UTC](https://discuss.elastic.co/t/custom-tokenfilter-plugin-class-initialization-and-parameter-validation/79472/1 "2017-03-21T16:43:10Z")

</div>

I have a custom TokenFilter I'm adding like this:

```
public class CompounderPlugin extends Plugin implements AnalysisPlugin {

 @Override
 public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
	 Map<String, AnalysisProvider<TokenFilterFactory>> extra = new HashMap<>();
	 extra.put("compounder", CompounderTokenFilterFactory::new);
	 return extra;
 }
}

```

The issue I'm having is that in my CompounderTokenFilterFactory constructor, I'm validating parameters that should be provided in the settings. However, since the constructor is called both when registering the plugin regardless of whether we have a custom filter in settings, it is not possible to validate a parameter. I have to set a default value. I don't want to set a default, I want a parameter to be required.

This is exactly how [https://github.com/elastic/elasticsearch/blob/5.2/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java](https://github.com/elastic/elasticsearch/blob/5.2/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java) works. The factory constructor validates that `word_list` is present and throws if it is missing. If I replicate this code in my factory constructor, it throws upon creating any index -- even one without settings.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 18, 2017, 4:43pm UTC](https://discuss.elastic.co/t/custom-tokenfilter-plugin-class-initialization-and-parameter-validation/79472/2 "2017-04-18T16:43:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
