An alternative of a regular expression repeats an earlier one, so it can never be the one that matches

tx0/java:regex-duplicate-alternativedefaultwarningbug

What it finds

(png|jpg|png) lists png twice. The second copy can never be the alternative that matches, since the first one is tried before it; it is usually a typo for another value that is now missing.

Reported is an alternative that is the same as an earlier one of the same choice.

From the rule's source, regex_duplicate_alternative.rs.

Example from the rule's tests
import java.util.regex.Pattern; class Files {  Pattern a = Pattern.compile("\\.(png|jpg|png)$");tx0 reports: repeats an earlier one  Pattern b = Pattern.compile("\\.(png|jpg|gif)$");}
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-duplicate-alternative" = "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-duplicate-alternative] reason="..."

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