0

I've just deployed a CI system based on jenkins plus sonarqube. Once Jenkins Sonnarscanner starts his part of the Pipeline I can see a lot of messages such as the following:

WARN: Invalid character encountered in file /var/jenkins_home/workspace/Pipeline Test/code/..../CodigoSitioDAO.java at line 3 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

Well, my sonarqube calling line is:

                                sh "${scannerHome}/bin/sonar-scanner \
                                -Dsonar.sourceEnconding=UTF-8 \
                                -Dsonar.projectKey=My_Project\
                                -Dsonar.sources=. \
                                -Dsonar.java.binaries=. \
                                -Dsonar.nodejs.executable=. \
                                -Dsonar.login=c9bb378b2380af844c7465424933b942d10f5d18 \
                                -Dsonar.host.url=http://sonarqube:9000"
                            }

So, once I've check the mentioned file, what I can see in line 3 is something that I think does not have to do with the warning messages: import java.sql.Connection;

Having also configured -Dsonar.sourceEncoding=UTF-8, I have to say that I don't know what is happenig.

Could anyone of you help me?

  • 1
    Assuming that you have copied and pasted your Jenkins pipeline, you have a typo in `-Dsonar.sourceEnconding`. Please correct it and check whether the issue is still happening. – raspy Feb 12 '21 at 13:32
  • Well, I've noticed that just after posting my message, but anyway thanks. I have fixed it, but I have to say that the warning remains... – Juan María Reina Ortiz Feb 15 '21 at 08:02
  • That still makes sense. The message means that the file is not in UTF-8 as it contains a byte sequence incorrect for UTF-8. Please investigate the file in some binary viewer what is actually around this line, maybe some unprintable character? You may also try to open the file in the text editor and re-save explicitly selecting UTF-8. – raspy Feb 15 '21 at 08:22
  • The file is in UTF-8... But, I've learned line count includes the commented out ones, so this file's line #3 is: * Prop�sito: Clase de implementaci�n del DAO de los c�digos que puede tener So, I'm affraid this isn't nothing more than I'm a newbee about this :) Again, thanks – Juan María Reina Ortiz Feb 15 '21 at 11:11

1 Answers1

0

It looks to me like the file is not in UTF-8. It's quite possible (especially if you used Windows editor) that the file is saved in some platform-specific encoding and its contents does not make sense for UTF-8. Consider the following:

Clase de implementación del DAO de los códigos

The same contents has been saved as ANSI and UTF-8 (explicitly selected upon save). Now if you compare byte contents, these are not the same:

$ hexdump -C test-ansi.txt
00000000  43 6c 61 73 65 20 64 65  20 69 6d 70 6c 65 6d 65  |Clase de impleme|
00000010  6e 74 61 63 69 f3 6e 20  64 65 6c 20 44 41 4f 20  |ntaci.n del DAO |
00000020  64 65 20 6c 6f 73 20 63  f3 64 69 67 6f 73        |de los c.digos|
0000002e

$ hexdump -C test-utf8.txt
00000000  43 6c 61 73 65 20 64 65  20 69 6d 70 6c 65 6d 65  |Clase de impleme|
00000010  6e 74 61 63 69 c3 b3 6e  20 64 65 6c 20 44 41 4f  |ntaci..n del DAO|
00000020  20 64 65 20 6c 6f 73 20  63 c3 b3 64 69 67 6f 73  | de los c..digos|
00000030

Note that the same character ó is encoded as f3 in ANSI and as c3 b3 in UTF-8. I believe this is what your message is about: declared encoding is UTF-8 (possibly default), but the character contents f3 is invalid under this encoding. Please double check your encoding with the hex editor.

Side note: if you copied and pasted your line directly from your file, please note that Stack Overflow was not able to decode it as well, confirming it's not UTF-8-encoded.

raspy
  • 3,995
  • 1
  • 14
  • 18
  • Thank you very much for the explanation. I did some further reseach and what I learned is that all this issues are because the current git repository contents were moved here from an old svn and the file transportation were not done taking care of encoding. – Juan María Reina Ortiz Feb 16 '21 at 13:34