S4248 Regex patterns should not be created needlessly - false positive

SonarQube 6.7.6
SonarJava 5.11

RSPEC-4248

String’s split method has an optimization that doesn’t create a regex if the parameter is a one character string. RegexPatternsNeedlesslyCheck tries to detect this case, but fails for “\n”.

The following code triggers S4248, when it shouldn’t.

String str = "abc";
str.split("\n");

Hey,

Thanks for the feedback. It’s indeed a FP. Ticket created to handle it: SONARJAVA-3088

Cheers,
Michael

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.