[false-negative]S3027 can not detect single unicode character like "\u001B"

Affects Sonarqube Version:
Sonarqube version:
sonar-scanner version:

S3027: String function use should be optimized for single characters

Unable to detect single unicode character like “\u001B”.
This rule is implemented in java-checks-!\org\sonar\java\checks\StringMethodsOnSingleCharCheck.java
This rule uses return argValue.length() == 2 && argValue.charAt(0) == ‘\’; to determine whether the string is a single character,
and does not apply to the case of single unicode characters.

Code Sample demonstrating the issue:

int aIndex = addString.indexOf("\u001B");

Expected outcome:

Running Sonarqube through:
command line


Thanks for taking the time to clearly report this false negative.

I understand that the rule could be improved, however, it is deprecated, it should not be used anymore and therefore it doesn’t make sense to improve it further.

In fact, the whole rule in itself is questionable, there is no strong evidence that what it is claiming is correct. You can find more information in this comment, and this ticket.

Hope this makes sense,