Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

[IndexOutOfBoundsException] Wrong offset xxx. Should be in range: [0, yyy] #106

Closed
JordanGoasdoue opened this issue Jan 28, 2020 · 4 comments
Labels
Milestone

Comments

@JordanGoasdoue
Copy link

SonarQube Scanner 4.2.0.1873
SonarQube Server 8.0.0 (I'm not using the latest sonarqube release 8.1 because of some support problem with another plugin I am using)
detekt sonar-kotlin 1.2.0

INFO: Scanner configuration file: /usr/lib/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /workspace/sonar-project.properties
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 4.15.0-74-generic amd64
INFO: User cache: /root/.sonar/cache
INFO: SonarQube server 8.0.0
INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=268ms
INFO: Server id: xxxxx
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=105ms
INFO: Load/download plugins (done) | time=14550ms
INFO: Process project properties
INFO: Process project properties (done) | time=4ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: zzzzzzzzzzzzzzz
INFO: Base dir: /workspace
INFO: Working dir: /workspace/.scannerwork
INFO: Load project settings for component key: 'zzzzzzzzzzzzzzz'
INFO: Load project branches
INFO: Load project branches (done) | time=49ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=48ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=0ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=174ms
INFO: Load active rules
INFO: Load active rules (done) | time=3140ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Load project repositories
INFO: Load project repositories (done) | time=40ms
INFO: 825 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for css: Sonar way
INFO: Quality profile for java: Sonar way
INFO: Quality profile for kotlin: detekt active
INFO: Quality profile for web: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: ------------- Run sensors on module zzzzzzzzzzzzzzz
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=62ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/root/.sonar/cache/866bb1adbf016ea515620f1aaa15ec53/sonar-javascript-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor JavaSquidSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
WARN: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property.
INFO: JavaClasspath initialization (done) | time=8ms
INFO: JavaTestClasspath initialization
INFO: JavaTestClasspath initialization (done) | time=0ms
INFO: Java Main Files AST scan
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: Java Main Files AST scan (done) | time=2620ms
INFO: Java Test Files AST scan
INFO: 0 source files to be analyzed
INFO: Java Test Files AST scan (done) | time=1ms
INFO: 0/0 source files have been analyzed
INFO: Sensor JavaSquidSensor [java] (done) | time=3061ms
INFO: Sensor SonarCSS Metrics [cssfamily]
INFO: Sensor SonarCSS Metrics [cssfamily] (done) | time=12ms
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=900ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=4ms
INFO: Sensor DetektSensor [kotlin]
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

514 kotlin files were analyzed.
INFO: RuleSet: comments - 0
INFO: RuleSet: complexity - 84
INFO: RuleSet: empty-blocks - 60
INFO: RuleSet: exceptions - 14
INFO: RuleSet: formatting - 2478
INFO: RuleSet: naming - 82
INFO: RuleSet: performance - 0
INFO: RuleSet: potential-bugs - 0
INFO: RuleSet: style - 523
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 42.039s
INFO: Final Memory: 18M/80M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IndexOutOfBoundsException: Wrong offset: 7450. Should be in range: [0, 7431]
	at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.LineSet.findLineIndex(LineSet.java:178)
	at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.DocumentImpl.getLineNumber(DocumentImpl.java:991)
	at org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils.offsetToLineAndColumn(PsiDiagnosticUtils.java:73)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax$processFile$1.invoke(KotlinSyntax.kt:23)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax$processFile$2.invoke(KotlinSyntax.kt:27)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax$processFile$3.invoke(KotlinSyntax.kt:51)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax$processFile$5.invoke(KotlinSyntax.kt:65)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax$processFile$5.invoke(KotlinSyntax.kt:15)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax.visitTokens(KotlinSyntax.kt:80)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax.visitTokens(KotlinSyntax.kt:81)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax.visitTokens(KotlinSyntax.kt:81)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax.visitTokens(KotlinSyntax.kt:81)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax.visitTokens(KotlinSyntax.kt:81)
	at io.gitlab.arturbosch.detekt.sonar.foundation.KotlinSyntax.processFile(KotlinSyntax.kt:63)
	at io.gitlab.arturbosch.detekt.sonar.sensor.FileProcessor.run(FileProcessor.kt:23)
	at io.gitlab.arturbosch.detekt.sonar.sensor.DetektSensor.execute(DetektSensor.kt:27)
	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:387)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:383)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:346)
	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)

Before updating the detekt sonar-kotlin to 1.2.0, I had the same error than this issue : #102

Now I have the one mentionned here.

Anyone having similar problem here ?

Thanks

arturbosch added a commit that referenced this issue Jan 28, 2020
Reporting the findings is more important than having all tokens properly highlighted. We print warnings to investigate this further in the future.
@arturbosch
Copy link
Member

arturbosch commented Jan 28, 2020

Hey,
thanks for reporting this.
I changed the logic to catch any errors when doing the syntax highlighting.
There might be some tokens not properly highlighted but I find having the issues reported is more important.
We will print any syntax problems on the console with the file name to have an easier way to track this errors in the future.

@arturbosch arturbosch added the bug label Jan 28, 2020
arturbosch added a commit that referenced this issue Jan 28, 2020
Reporting the findings is more important than having all tokens properly highlighted. We print warnings to investigate this further in the future.
arturbosch added a commit that referenced this issue Jan 28, 2020
Reporting the findings is more important than having all tokens properly highlighted. We print warnings to investigate this further in the future.
arturbosch added a commit that referenced this issue Jan 28, 2020
* Use https to fetch dependencies from jcenter

* Catch all errors on invalid syntax highlighting - #106

Reporting the findings is more important than having all tokens properly highlighted. We print warnings to investigate this further in the future.

* Update to detekt 1.5.0

* Prepare 1.3.0 release

* Fix max line issue
@JordanGoasdoue
Copy link
Author

Thank you @arturbosch and @jvilya , it works now in sonar-kotlin v1.3.0 , with the fix from #108

@vandrwinte
Copy link

Hello,

These highlighting problems seem to be a result of style/formatting rules doing autocorrect during analysis.
That causes PSI representation of code to differ from the source. Sonarqube API expects offsets for original version, hence messy highlighting or exceptions thrown.

Disparity is not there where KtFile objects are first created, seems like it occurs after KtLintMultiRule runs (which if I'm not mistaken is class with formatting rules).

Currently, one workaround to this issue is supplying .yml config with autoCorrect set to false.
Could plugin be changed to have this feature be turned off by default? At least until there is some better way to handle it.

@arturbosch
Copy link
Member

Hello,

These highlighting problems seem to be a result of style/formatting rules doing autocorrect during analysis.
That causes PSI representation of code to differ from the source. Sonarqube API expects offsets for original version, hence messy highlighting or exceptions thrown.

Disparity is not there where KtFile objects are first created, seems like it occurs after KtLintMultiRule runs (which if I'm not mistaken is class with formatting rules).

Currently, one workaround to this issue is supplying .yml config with autoCorrect set to false.
Could plugin be changed to have this feature be turned off by default? At least until there is some better way to handle it.

Hey, thanks for investigating this.
If your workaround works perfectly than we have a serious regression here.
sonar-kotlin should normally deactivate the autoCorrect-feature -> https://github.com/detekt/sonar-kotlin/blob/58caff8519893303971c362144079d2b5afe78a0/src/main/kotlin/io/gitlab/arturbosch/detekt/sonar/foundation/NoAutoCorrectConfig.kt

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants