Invalid character encountered in file

2,857 views
Skip to first unread message

Charles Morin

unread,
Jul 11, 2016, 8:45:49 AM7/11/16
to SonarQube
Hi,

Is there a way to fix this easily?
[sonar:sonar] Invalid character encountered in file PATH_TO_FILE at line 25 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

The character that is causing the warning is a single quote, which is used quite often in Javadoc in the French language.

Is there a way to escape this or have it fixed?

Thank you

Charles

Charles Morin

unread,
Jul 11, 2016, 8:51:56 AM7/11/16
to SonarQube
I've forgot to mention that I have the following property in my Ant build script:
sonar.sources.sourceEncoding=UTF-8

Taken from:
http://docs.sonarqube.org/display/SONAR/Analysis+Parameters

G. Ann Campbell

unread,
Jul 11, 2016, 8:57:39 AM7/11/16
to SonarQube
Hi Charles,

Is this a curly quote or straight quote?


Ann

Charles Morin

unread,
Jul 11, 2016, 9:00:44 AM7/11/16
to SonarQube
Straight quote, just like '
http://www.ascii.cl/htmlcodes.htm

Thank you

Charles Morin

unread,
Jul 11, 2016, 9:13:04 AM7/11/16
to SonarQube
It also bogs down when finding accents like é è ê etc...

All these are common characters for the french language.

Julien HENRY

unread,
Jul 12, 2016, 8:37:29 AM7/12/16
to SonarQube
Hi guys,

Is your file really encoded in UTF-8?
My guess if you are on Windows is that the encoding is ISO-8859-1.

An option is to open the file with an Hexadecimal editor to get the real bytes and find the encoding (I doubt a straight quote will cause the issue since it is the same encoding in UTF-8 and in ISO-8859-1).

For a 'é' character, encoding is:
  UTF-8: a9c3 000a
 ISO-8859-1: 0ae9

++

Julien

Charles Morin

unread,
Jul 12, 2016, 12:29:30 PM7/12/16
to SonarQube
I am indeed on Windows. After reviewing my Eclipse properties (under Window > Preferences > Workspace), Text file encoding is set to Cp1252. Would it make sense to switch it to UTF-8?

Thanks

Charles Morin

unread,
Jul 12, 2016, 2:26:47 PM7/12/16
to SonarQube
I have finally used ISO-8851-1 for the sonar.sources.sourceEncoding parameter and it worked. No more warning.

Thank you all

Charles


On Tuesday, July 12, 2016 at 8:37:29 AM UTC-4, Julien HENRY wrote:
Reply all
Reply to author
Forward
0 new messages