java.lang.IllegalArgumentException: XXX is not a valid line for pointer

Versions used

SonarQube 8.2.0.32929 Developer edition
SonarScanner 4.3.0.2102 (official sonarsource/sonar-scanner-cli:4.3 image)
Plugin SonarSwift 4.2.2 (build 77)

Errors observed

13:14:43.685 INFO: ------------------------------------------------------------------------
 13:14:43.685 INFO: EXECUTION FAILURE
 13:14:43.686 INFO: ------------------------------------------------------------------------
 13:14:43.686 INFO: Total time: 1:18.484s
 13:14:43.918 ERROR: Error during SonarScanner execution
 13:14:43.918 INFO: Final Memory: 139M/470M
 13:14:43.918 INFO: ------------------------------------------------------------------------
 java.lang.IllegalArgumentException: 516 is not a valid line for pointer. File src/classes/AppLaunchCoordinator.swift has 497 line(s)
 	at org.sonar.api.utils.Preconditions.checkArgument(Preconditions.java:43)
 	at org.sonar.api.batch.fs.internal.DefaultInputFile.checkValid(DefaultInputFile.java:336)
 	at org.sonar.api.batch.fs.internal.DefaultInputFile.newPointer(DefaultInputFile.java:272)
 	at org.sonar.api.batch.fs.internal.DefaultInputFile.selectLine(DefaultInputFile.java:295)
 	at com.sonar.swift.plugin.external.SwiftLintSensor.reportSwiftLintIssue(Unknown Source)
 	at com.sonar.swift.plugin.external.SwiftLintSensor.importReport(Unknown Source)
 	at com.sonar.swift.plugin.external.SwiftLintSensor.lambda$execute$1(Unknown Source)
 	at java.base/java.util.ArrayList.forEach(Unknown Source)
 	at com.sonar.swift.plugin.external.SwiftLintSensor.execute(Unknown Source)
 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
 	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
 	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
 	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
 	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Steps to reproduce

We don’t know… it happens with different files, at random times, on files that aren’t modified in the branch/MR that we are scanning. This makes the analysis be ignored by our developers, as they are getting false positives about their code failing.

The logs are telling me that you have a SwiftLint report being imported that says there’s an issue at line 516 of src/classes/AppLaunchCoordinator.swift – but that the file as read by SonarQube only has 497 lines.

Can you verify either of those points? Could the SwiftLint report be outdated?

1 Like

Hi Colin,

Yep, that’s what I’m getting from the error as well, but this error doesn’t really make sense for us. That file hasn’t been modified in one month. I’m not fully familiar with how SonarQube reports are working, but why would the report be outdated?

We scan the whole codebase on each commit push, the files always change in length, not sure why that would be a problem. What it’s being compared against in this case? When does it import the report and from where?

And regarding the SwiftLint version, as far as I can see we are using the latest version, so unless it’s a bug on it I’m not sure what else we can do with it.

Oops… hold up… I was confusing SwiftLint and SonarSwift… sorry for that. Let me check.

My point was not about the version of SwiftLint, but whether the generated reported (being passed to sonar.swift.swiftLint.reportPaths when Importing External Issues was generated specifically for the code being scanned (as opposed to an old report)

Hi, I’m the maintainer of the pipeline this is happening on.

Regarding your question: both the sonar scanner and SwiftLint are run as part of the same gitlab pipeline, albeit in different jobs (and docker containers). Both jobs show the same commit being checked out.

What I find most interesting is that the line number the scanner reports in the exception doesn’t actually appear in the JSON that SwiftLint outputs. In some cases (like the one posted here), the JSON being imported doesn’t even mention that file (AppLaunchCoordinator.swift).

I noticed that the JSON used absolute paths for source files so I tried switching to the generic SonarQube format instead, for which SwiftLint uses relative paths. Today the issue occurred even with that format, though.

Is there any more info we can provide that could help?

Are you 100% sure about that? That’s sounds unlikely in case you do everything correctly (generate report and import it on the same code base).

Quite sure, though it does seem like the file is for a different ref than what the scanner runs on. Not sure how that’s possible.

On another pipeline, we’ve just received this error:

java.lang.IllegalStateException: Failed to read external issues report '/builds/mobile/ios/artifacts/swiftlint.json': invalid JSON syntax

…even though the JSON is the same as on another pipeline where the scanner passed with no issues. That too would suggest (to me) that the problem is with the version of the file being passed to the scanner :thinking:

I archive the thread as being old, please open a new one if problem persists.