Sonar Scan Failure for Line Out-of-Range

Dear Sonar experts,

We keep getting Sonar error complaining code line out of range. The error message is:

java.lang.IllegalStateException: Line 92 is out of range in the file xxxxx.cpp (lines: 90)

The code it complains on has only 90 lines, we don’t understand how Sonar would expect line 92. Our CI does not use any cache, all analysis are from clean checkout and clean build.

This error can be eliminated by adding some empty lines in the end of the file, but we don’t want to keep empty lines in our code base for this reason.

Could anyone help on how to solve this ?

Many thanks,
Yi

Hey there.

You’ve not included some information from the template post:

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

It would also be helpful for you to provide a wider range of logs, to understand where in the scan you are getting this error.

Experiencing the same with c#

System info:
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
SonarScanner for MSBuild 5.7.1
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.1 Oracle Corporation (64-bit)
INFO: Windows Server 2016 10.0 amd64

Sonar server: Developer Edition Version 8.9.9 (build 56886)

Error:
java.lang.IllegalStateException: Line 87 is out of range in the file REDACTED (lines: 85)

Searched Issues · SonarSource/sonar-scanner-msbuild · GitHub for open and closed issues but didn’t find anything.

@pregress As recommended to @yd.endress – a wider range of logs (not just the single line) would help in understanding when/where during analysis the issue occurs.

I had the same issue. It was because I had some old coverage.xml files. I deleted them, and the scan worded successfully.

1 Like

forzagreen Yep, had same issue, thank you!