A pattern string is malformed, so Pattern.compile throws
What it finds
line.split("("), Pattern.compile("[a-z") and text.replaceAll("{name}", value) throw a PatternSyntaxException the first time they run: the pattern is not valid in the syntax of java.util.regex.Pattern. Common causes are unescaped parentheses, brackets and braces, quantifiers with nothing to repeat, ranges that run backwards and escapes that Pattern does not define.
Reported is a pattern written as a string literal, or a concatenation of literals, given to Pattern.compile, Pattern.matches, or matches, split, replaceAll or replaceFirst of a String, that Pattern.compile would reject.
From the rule's source, invalid_regex.rs.
import java.util.regex.Pattern; class Parse { void run(String text) { String[] a = text.split("(");tx0 reports: does not compile: a group is not closed Pattern b = Pattern.compile("[a-z");tx0 reports: does not compile: a [ is not closed String c = text.replaceAll("{name}", "x");tx0 reports: does not compile: a { does not start a repetition boolean d = text.matches("\\i+");tx0 reports: is not an escape Pattern e = Pattern.compile("[z-a]");tx0 reports: a range in a class runs backwards Pattern f = Pattern.compile("(?<year>\\d{4})-\\k<year>"); String[] g = text.split("\\("); Pattern h = Pattern.compile("[]a]"); }} 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:invalid-regex" = "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:invalid-regex] reason="..."tx0 explain tx0/java:invalid-regex shows the same in the terminal. Found a false positive? Report it.