[Java] S2639 raises no issue for String.replaceFirst()

java

(Oliver Goroll) #1

The rule S2639 checks whether the first argument to String.replaceAll(regex, replacement) is inappropriate, that is either “.” or “|”; a common mistake is string.replaceAll(".", "");, removing all text.
However, for String.replaceFirst(regex, replacement) no issue is raised. I’d say that string.replaceFirst(".", "x"); intends to replace the first dot character and not the first character and the rule should also check replaceFirst().
There is a corresponding FindBugs rule (RE_POSSIBLE_UNINTENDED_PATTERN) which does check both.