Affects Version/s: 3.5
Fix Version/s: 4.0-ALPHA
Solr sometimes crashes with an unhelpful stack trace. If the PatternTokenizerFactory's "pattern" attribute is set to an invalid regular expression, a PatternSyntaxException is thrown and Solr fails to start. The PatternSyntaxException is not useful to users in diagnosing the error. I think it would be better to report a detailed error message. The attached patch makes this change.
Note that the patch adds a small RegexUtil class with helper methods to determine whether a String is a valid regular expression and to generate error messages for invalid regular expressions. I feel that these helper methods are more readable than catching the PatternSyntaxException. Furthermore, they can be re-used if more bugs like this one are found.
Steps to reproduce:
- Patch in bug.patch
- Note that this sets PatternTokenizerFactory's pattern attribute to an invalid regular expression.
- Run 'ant run-example' from the solr folder
- See exception in console output on startup:
4. Visit http://localhost:8983/solr/admin/ and see a similar message:
After applying the patch, the following is printed to the console:
And the following similar message is shown when visiting http://localhost:8983/solr/admin/ :