Ant sonarcheck jacoco coverage XML issues

Hi,
We just upgraded the sonarqube to 8.4 from 7.5 as we were not able to install any new tools in it. After the upgrade we ran the analysis for our SAP ant based project and seeing below errors while uploading the coverage to sonarqube.

sonar:sonar] Coverage report ‘/data/log/jacoco/reports/jacoco.xml’ could not be read/imported. Error: {}
[sonar:sonar] java.lang.IllegalStateException: Failed to parse JaCoCo XML report: /data/hybris/hybris/log/jacoco/reports/jacoco.xml
[sonar:sonar] at org.sonar.plugins.jacoco.XmlReportParser.parse(XmlReportParser.java:108)
[sonar:sonar] at org.sonar.plugins.jacoco.JacocoSensor.importReport(JacocoSensor.java:70)
[sonar:sonar] at org.sonar.plugins.jacoco.JacocoSensor.importReports(JacocoSensor.java:62)
[sonar:sonar] at org.sonar.plugins.jacoco.JacocoSensor.execute(JacocoSensor.java:47)
[sonar:sonar] at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
[sonar:sonar] at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
.
.


[sonar:sonar] Caused by: com.ctc.wstx.exc.WstxIOException: Input length = 1
[sonar:sonar] at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:550)
[sonar:sonar] at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:605)
[sonar:sonar] at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:658)
[sonar:sonar] at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:338)
[sonar:sonar] at org.sonar.plugins.jacoco.XmlReportParser.parse(XmlReportParser.java:51)
[sonar:sonar] … 63 common frames omitted
[sonar:sonar] Caused by: java.nio.charset.MalformedInputException: Input length = 1
[sonar:sonar] at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:274)
[sonar:sonar] at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
[sonar:sonar] at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
[sonar:sonar] at java.base/java.io.InputStreamReader.read(InputStreamReader.java:185)
[sonar:sonar] at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
[sonar:sonar] at java.base/java.io.BufferedReader.read1(BufferedReader.java:212)
[sonar:sonar] at java.base/java.io.BufferedReader.read(BufferedReader.java:287)
[sonar:sonar] at com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.java:250)
[sonar:sonar] at com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.java:133)
[sonar:sonar] at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:545)
[sonar:sonar] … 67 common frames omitted
[sonar:sonar] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms

is anyone seen this issue. I read that this could be resolved by setting “sonar.sourceEncoding=UTF-8” but its not helping.

Thanks,
Mayuresh

Checking if anyone have seen the similar issues?

Hello @mayuresh,

I’m quite sure sonar.sourceEncoding only applies to source files, not reports, so I don’t think this would make any difference.

This Java exception java.nio.charset.MalformedInputException is likely about some encoding issue. The default JaCoCo outputEncoding is UTF-8, is it something that you changed somehow?
You should open and review your XML report to check if it’s valid or what is going on with it.

Cheers

Hi Antonie,
I checked the XML and i am seeing some weird data like below.

5>ô^K^@2com/Stock"^A^@^@ª^B^Q^EñÍßÚ¼Mm^@4com/Enum ^?^@Àv^AÀÀ^P^G^P^^@^@^Ast<82>î^@^@^Ast<86>õÏ^Q<97>pV«^Qø<9c>!^@Zcom/Strategy^Y^C^@^@^A^Q<87>^X^V3ä,1^E^@acom/Converter^B^A^Q^X<89><92>Ù#F]^S^@Pcom DefaultUserPreferenceService<8e>^C^C^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^Q®h<93>&ÿ<9a>^BÑ^@Tcom/facades/bazaarvoice/impl/<97>^A^G^@^@^@^@^@^@^@^@@^A^@^@^@^@^@^@XU^Qü¿<94>¦y^NÝ^R^@Acom/impl/DefaultFacetedService[^C^@^@^@^@^@^@^@^@^@^@^@^Q¥´ã<8a>\e2^@7com/

That looks like something binary. Are you sure it’s not the JaCoCo data file that needs to be processed by JaCoCo’s report task to produce the XML report?

Below is my configuration that i am using to process.

#Sonar Properties

sonar.projectName=<NAME>

sonar.projectKey=<KEY/>

sonar.host.url=<URL>

sonar.login=<API_KEY>

sonar.language=java

clustermode=false

sonar.verbose=true

sonar.sourceEncoding=UTF-8

sonar.java.coveragePlugin=jacoco

sonar.coverage.jacoco.xmlReportPaths=<PATH>/reports/jacoco.xml

sonar.extensions=extension1,extension2,extension3,extension4

sonar.inclusions=**/*.java

sonar.exclusions=**/jalo/**/*.java,**/constants/**/*.java,**/dto/**/*.java,**/*DTO.java,**/dtos/**/*.java,**/integ/webservices/**/*.java,**/*Standalone.java,**/gensrc/**/*.java,**/request/**/*.java,**/result/**/*.java,**/data/**/*.java,*/*Controller.java,**/Jalo/**/*.java,**/*Form.java

sonar.coverage.exclusions=*WebHelper.java,**/jalo/**/*.java,**/constants/**/*.java,**/dto/**/*.java,**/*DTO.java,**/dtos/**/*.java,**/integ/webservices/**/*.java,**/*Standalone.java,**/gensrc/**/*.java,**/request/**/*.java,**/result/**/*.java,**/data/**/*.java,*/*Controller.java,**/Jalo/**/*.java,**/*Form.java,**/*DTO.java

sonar.web.file.suffixes=.jsp,.tag

sonar.junit.reportsPath=<path_to_junit>/junit

standalone.javaoptions=-javaagent:${BIN_DIR}/platform/resources/ant/sonar/lib/jacocoagent.jar=destfile=<PATH>/reports/jacoco.xml,append=true,excludes=com.google.*:com.sun.*:de.hybris.*:org.mockito.*:org.junit.*:org.apache.*,includes=<our_package>

The properties aren’t necessarily the problem. It looks like the file <PATH>/reports/jacoco.xml is a binary file. It should be the XML report that the JaCoCo’s report task outputs. I’d check if JaCoCo is correctly set up to install the agent during the execution of the tests (producing a binary data file) and that it processes that file to produce the XML report that should then be imported with the SonarQube scanner.