A possessive quantifier takes the characters that the next part of the regular expression needs, so it never matches
What it finds
.*+x never matches: a possessive quantifier takes as much as it can and gives nothing back, so .*+ eats the x too and the pattern fails at the x. A possessive quantifier is only safe when what follows cannot match what it repeats.
Reported is an unbounded possessive quantifier on a single character, class or ., followed directly by a character that it also matches.
From the rule's source, regex_possessive_starves.rs.
import java.util.regex.Pattern; class Possessive { Pattern a = Pattern.compile(".*+x");tx0 reports: takes the character that follows it Pattern b = Pattern.compile("[a-z]++c");tx0 reports: takes the character Pattern c = Pattern.compile("[a-z]++1"); Pattern d = Pattern.compile(".*x");} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:regex-possessive-starves" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:regex-possessive-starves] reason="..."tx0 explain tx0/java:regex-possessive-starves shows the same in the terminal. Found a false positive? Report it.