A string is split at a single regular expression metacharacter
What it finds
line.split(".") returns an empty array: split takes a regular expression, and . matches every character. split("|") splits between every two characters, split("$") does not split at all, and split("+"), split("*") and split("?") throw. Escaped, as in split("\\."), the character stands for itself.
Only receivers known to be strings are reported. The fix escapes the character, which changes the result to the one meant, so it is offered as unsafe.
From the rule's source, split_metacharacter.rs.
class Paths { String[] parts(String path, java.util.regex.Pattern pattern) { String[] a = path.split(".");tx0 reports: in which . matches every character String[] b = path.split("|", 2);tx0 reports: in which | matches the empty string String[] c = path.split("+");tx0 reports: is not a valid regular expression String[] d = path.split("\\."); String[] e = path.split("/"); String[] f = pattern.split("."); return a.length > 0 ? a : b.length > 0 ? b : c.length > 0 ? c : d.length > 0 ? d : e.length > 0 ? e : f; }} 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:split-metacharacter" = "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:split-metacharacter] reason="..."tx0 explain tx0/java:split-metacharacter shows the same in the terminal. Found a false positive? Report it.