A pattern refers back to a capture that does not exist yet at that point

tx0/java:regex-unmatched-backreferencedefaulterrorbug

What it finds

(a)\2 refers to a second group that does not exist, and \1(a) to a group that has not matched yet when the reference is reached: such a reference never matches, so the whole alternative never does. Pattern reads a back reference by number without checking that the group exists before it.

Reported is a numbered back reference to a group that is not opened before it in the pattern.

From the rule's source, regex_unmatched_backreference.rs.

Example from the rule's tests
import java.util.regex.Pattern; class Refs {  Pattern a = Pattern.compile("(a)\\2");tx0 reports: refers to a group that is not defined before it  Pattern b = Pattern.compile("\\1(a)");tx0 reports: refers to a group  Pattern c = Pattern.compile("(a)\\1");}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/java:regex-unmatched-backreference" = "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-unmatched-backreference] reason="..."

tx0 explain tx0/java:regex-unmatched-backreference shows the same in the terminal. Found a false positive? Report it.