Product
- SonarLint for Eclipse 12.4.0.84771
- Eclipse 2026-06 (4.40)
- Java 17
Rule
java:S8786 – Regular expressions should not cause non-linear backtracking.
Problem
SonarLint reports java:S8786 on the following regex:
import java.util.regex.Pattern;
class Test {
private static final Pattern NUMBER_PATTERN =
Pattern.compile("\\d+$");
}
The issue is reported on the Pattern.compile(...) call.
I believe this is a false positive because the pattern consists only of:
- a single character class (
\d) - one greedy quantifier (
+) - an end-of-string anchor (
$)
There are no nested quantifiers, alternations, optionals or lookarounds that could lead to non-linear backtracking.
I also tried the following equivalent patterns, all of which trigger the same warning:
Pattern.compile("(\\d+)$");
Pattern.compile("\\d++$");
Pattern.compile("[0-9]+$");
Pattern.compile("\\p{Digit}+$");
Could you please confirm whether this is a false positive?
Thanks!