Must-share information (formatted with Markdown):
- Sonarqube 8.3
- error free scan of java source files
I have a couple of files in my repository that use the replacement character in strings.
Example (and I realize that everyone may see something different here)
String s = “[“abc�”]”;
These are mostly used as tests for validating our strings can be truncated as expected and whatnot.
This leads to problems with our scanner:
…pathToMyUnitTest.java at line 177 for encoding UTF-8. Please fix file content or configure the encoding to be used using property ‘sonar.sourceEncoding’.
These error show in the scanner output. While they seem ignorable, if I understand correctly, that means this file won’t be scanned at all.
This is sort of related to Invalid character warning UTF-8
I tried setting sourceEncoding to UTF-8 and that made no difference as expected.
The only workaround I have found is to convert the string to something like:
tring specialWithReplacementChar = “[“abc” + “\uFFFD” + “”]”;
Which works, but makes the intent of the test harder to understand.
Has anyone come up with a better best practice that allows the <?> character to be used in the string so that the intent is more clear but also allows the scanner to work with the file?