replaceAll is given a pattern with no regular expression syntax
What it finds
text.replaceAll("-", "_") compiles a regular expression on every call to replace a plain string. When the pattern has no character with a meaning in regular expressions and the replacement has no $ or \, replace does the same without the regex. The fix calls replace.
From the rule's source, regex_replace_literal.rs.
class Slugs { String slug(String title) { String a = title.replaceAll("-", "_");tx0 reports: replaceAll with a plain pattern can be replace String b = title.replaceAll("\\s+", "-"); String c = title.replaceAll("x", "$0"); return a + b + c; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:regex-replace-literal" = "warning"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-replace-literal] reason="..."tx0 explain tx0/java:regex-replace-literal shows the same in the terminal. Found a false positive? Report it.