With SonarQube Developer Edition Version 8.9.2 (build 46101) I get the S5860 for the following Java code:
private static final Pattern TRAILING_NUMERATOR =
Pattern.compile("^.*[^\\d]0*(?<numerator>\\d+)$");
public static String trimTrailingNumerator(String text) {
var str = text;
var matcher = TRAILING_NUMERATOR.matcher(text);
if (matcher.matches()) {
str = str.substring(0, matcher.start("numerator"));
}
return str;
}
IMHO the named group is used in line 8 of the sample. Maybe it is not recognized because the code don’t uses Matcher.group to retrieve the groups text.
Oh and don’t mind the security issue of the pattern. I’m on it.