Error in sonar-scanner: "EncodingManager.getInstance must not return null"

If your question is about SonarLint in the IntelliJ Platform, VS Code, Visual Studio, or Eclipse, please post it in that sub-category.

Otherwise, please provide:

  • Operating system:
    Centos 7.9
  • IDE name and flavor/env:
    use the cmd of sonar-scanner-4.2.0.1873.

And a thorough description of the problem / question:

15:18:34.942 DEBUG: 'test/Test.kt' generated metadata with charset 'UTF-8'
15:18:34.999 INFO: ------------------------------------------------------------------------
15:18:34.999 INFO: EXECUTION FAILURE
15:18:34.999 INFO: ------------------------------------------------------------------------
15:18:34.999 INFO: Total time: 2:22.325s
15:18:35.308 INFO: Final Memory: 25M/200M
15:18:35.308 ERROR: Error during SonarQube Scanner execution
15:18:35.308 INFO: ------------------------------------------------------------------------
java.lang.IllegalStateException: @NotNull method org/jetbrains/kotlin/com/intellij/openapi/vfs/encoding/EncodingManager.getInstance must not return null
	at org.jetbrains.kotlin.com.intellij.openapi.vfs.encoding.EncodingManager.$$$reportNull$$$0(EncodingManager.java)
	at org.jetbrains.kotlin.com.intellij.openapi.vfs.encoding.EncodingManager.getInstance(EncodingManager.java:39)
	at org.jetbrains.kotlin.com.intellij.openapi.vfs.encoding.EncodingRegistry.getInstance(EncodingRegistry.java:43)
	at org.jetbrains.kotlin.com.intellij.openapi.vfs.VirtualFile.getCharset(VirtualFile.java:498)
	at org.jetbrains.kotlin.com.intellij.testFramework.LightVirtualFile.contentsToByteArray(LightVirtualFile.java:120)
	at org.jetbrains.kotlin.com.intellij.testFramework.LightVirtualFileBase.getLength(LightVirtualFileBase.java:160)
	at org.jetbrains.kotlin.com.intellij.psi.SingleRootFileViewProvider.fileSizeIsGreaterThan(SingleRootFileViewProvider.java:214)
	at org.jetbrains.kotlin.com.intellij.psi.SingleRootFileViewProvider.isTooLargeForIntelligence(SingleRootFileViewProvider.java:183)
	at org.jetbrains.kotlin.com.intellij.psi.SingleRootFileViewProvider.calcBaseLanguage(SingleRootFileViewProvider.java:92)
	at org.jetbrains.kotlin.com.intellij.psi.SingleRootFileViewProvider.<init>(SingleRootFileViewProvider.java:65)
	at org.jetbrains.kotlin.com.intellij.psi.SingleRootFileViewProvider.<init>(SingleRootFileViewProvider.java:58)
	at org.jetbrains.kotlin.com.intellij.psi.impl.PsiFileFactoryImpl.trySetupPsiForFile(PsiFileFactoryImpl.java:119)
	at org.jetbrains.kotlin.com.intellij.psi.impl.PsiFileFactoryImpl.createFileFromText(PsiFileFactoryImpl.java:88)
	at org.jetbrains.kotlin.com.intellij.psi.impl.PsiFileFactoryImpl.createFileFromText(PsiFileFactoryImpl.java:73)
	at org.jetbrains.kotlin.com.intellij.psi.impl.PsiFileFactoryImpl.createFileFromText(PsiFileFactoryImpl.java:67)
	at org.jetbrains.kotlin.com.intellij.psi.impl.PsiFileFactoryImpl.createFileFromText(PsiFileFactoryImpl.java:61)
	at org.jetbrains.kotlin.com.intellij.psi.PsiFileFactory.createFileFromText(PsiFileFactory.java:54)
	at org.sonarsource.kotlin.converter.KotlinConverter$KotlinTree.<init>(KotlinConverter.java:118)
	at org.sonarsource.kotlin.converter.KotlinConverter.parse(KotlinConverter.java:71)
	at org.sonarsource.slang.plugin.SlangSensor.lambda$analyseFile$0(SlangSensor.java:118)
	at org.sonarsource.slang.plugin.DurationStatistics.time(DurationStatistics.java:75)
	at org.sonarsource.slang.plugin.SlangSensor.analyseFile(SlangSensor.java:118)
	at org.sonarsource.slang.plugin.SlangSensor.analyseFiles(SlangSensor.java:92)
	at org.sonarsource.slang.plugin.SlangSensor.execute(SlangSensor.java:154)
	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:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	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)

Hey there.

Kotlin being analyzed by slang? :open_mouth: that looks really old. What version of SonarQube or SonarLint are you using?