Report issues on line numbers that are out of range in the file and throwing errors

Sonar is reporting issues on line numbers that are out of range in the file, and it’s generating the following errors.

For example, below mentioned file has 140 lines, but sonar reporting issues at 142 line.
r4e-report/src/main/java/com/reputation/report/utils/ReportUtils.java

Could you please assist us with this?

[ERROR] Cannot import coverage information for file 'r4e-report/src/main/java/com/reputation/report/utils/ReportUtils.java', coverage data is invalid. Error: {}
java.lang.IllegalStateException: Line 142 is out of range in the file r4e-report/src/main/java/com/reputation/report/utils/ReportUtils.java (lines: 141)
	at org.sonar.api.utils.Preconditions.checkState(Preconditions.java:61)
	at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:67)
	at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(DefaultCoverage.java:55)
	at org.sonar.plugins.jacoco.ReportImporter.importCoverage(ReportImporter.java:45)
	at org.sonar.plugins.jacoco.JacocoSensor.importReport(JacocoSensor.java:81)

Hey there.

What version of SonarQube are you using? This information is requested in the template post.

Hi Colin,

Thanks for looking into this issue.

We are using the SonarCloud, not the SonarQube.

Thanks & Regards,
Madhu

Okay. :slight_smile: You put the thread in the SonarQube category. I’ve moved it.

The error you’re receiving indicates that there are lines referenced in the coverage report that don’t exist in the source file. You can check (manually) the JaCoCo report XML file and, if it’s indeed referencing a line of a file that doesn’t exist, you’ll have to fix that issue by the source (either by generating a new coverage report, which you should be doing on every build before SonarQube analysis, or filing an issue with JaCoCo).