S4248 Regex patterns should not be created needlessly - false positive

java
(Davehoch) #1

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");
(Michael Gumowski) #3

Hey,

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

Cheers,
Michael

1 Like