Company
Date Published
Author
Sebastian Hungerecker
Word count
881
Language
English
Hacker News points
None

Summary

The Java programming language has a limitation when it comes to regular expressions, specifically that matching a pattern may require stack space proportional to the length of the input, which can cause the program to crash with a StackOverflowException. To address this issue, SonarCloud has implemented rules to detect and prevent regular expression-related problems, including stack overflows. These rules include java:S5998, which warns about regular expressions that overflow the stack, and java:S6035, which suggests replacing single-character alternations with character classes to avoid similar issues. Possessive quantifiers can be used to avoid catastrophic backtracking and stack consumption, but using them incorrectly can lead to problems. The rules also provide suggestions for fixing these issues, such as enabling the DOTALL flag or removing alternations that can be replaced with character classes.