SonarScanner failed scanning new project

During the first run of the scanner on my project, it failed with an error. A web search did not turn up anything obviously useful:

  • Versions:

INFO: SonarScanner 4.4.0.2170
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Mac OS X 10.15.6 x86_64

  • Error observed:
ERROR: Error during SonarScanner execution
java.lang.RuntimeException: org.scalameta.invariants.InvariantFailedException: invariant failed:
when verifying scala.meta.internal.trees.`package`.XtensionTreesType(tpe).isConstructable
found that scala.meta.internal.trees.`package`.XtensionTreesType(tpe).isConstructable is false
where tpe = (String, Boolean)
	at com.google.common.base.Throwables.propagate(Throwables.java:241)
	at org.sonar.core.platform.PicoUtils.propagate(PicoUtils.java:45)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:139)
	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)
Caused by: org.scalameta.invariants.InvariantFailedException: invariant failed:
when verifying scala.meta.internal.trees.`package`.XtensionTreesType(tpe).isConstructable
found that scala.meta.internal.trees.`package`.XtensionTreesType(tpe).isConstructable is false
where tpe = (String, Boolean)
	at org.scalameta.invariants.InvariantFailedException$.raise(Exceptions.scala:15)
	at scala.meta.Init$.internal$211(Trees.scala:340)
	at scala.meta.Init$.apply(Trees.scala:339)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$initRest$1(ScalametaParser.scala:3048)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.initRest(ScalametaParser.scala:3032)
	at scala.meta.internal.parsers.ScalametaParser.initInsideTemplate(ScalametaParser.scala:3020)
	at scala.meta.internal.parsers.ScalametaParser.readInit$1(ScalametaParser.scala:3096)
	at scala.meta.internal.parsers.ScalametaParser.templateParents(ScalametaParser.scala:3098)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$template$1(ScalametaParser.scala:3118)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.template(ScalametaParser.scala:3103)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$simpleExpr$7(ScalametaParser.scala:1879)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$simpleExpr$1(ScalametaParser.scala:1879)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.simpleExpr(ScalametaParser.scala:1837)
	at scala.meta.internal.parsers.ScalametaParser.prefixExpr(ScalametaParser.scala:1828)
	at scala.meta.internal.parsers.ScalametaParser.postfixExpr(ScalametaParser.scala:1808)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$expr$11(ScalametaParser.scala:1500)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$expr$1(ScalametaParser.scala:1500)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.expr(ScalametaParser.scala:1428)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$expr$12(ScalametaParser.scala:1505)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$expr$1(ScalametaParser.scala:1505)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.expr(ScalametaParser.scala:1428)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$blockStatSeq$2(ScalametaParser.scala:3353)
	at scala.meta.internal.parsers.ScalametaParser.stat(ScalametaParser.scala:3222)
	at scala.meta.internal.parsers.ScalametaParser.blockStatSeq(ScalametaParser.scala:3353)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$block$1(ScalametaParser.scala:1984)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.block(ScalametaParser.scala:1984)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$blockExpr$2(ScalametaParser.scala:1979)
	at scala.meta.internal.parsers.ScalametaParser.inBraces(ScalametaParser.scala:312)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$blockExpr$1(ScalametaParser.scala:1978)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.blockExpr(ScalametaParser.scala:1977)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$simpleExpr$1(ScalametaParser.scala:1874)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.simpleExpr(ScalametaParser.scala:1837)
	at scala.meta.internal.parsers.ScalametaParser.prefixExpr(ScalametaParser.scala:1828)
	at scala.meta.internal.parsers.ScalametaParser.postfixExpr(ScalametaParser.scala:1808)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$expr$11(ScalametaParser.scala:1500)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$expr$1(ScalametaParser.scala:1500)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.expr(ScalametaParser.scala:1428)
	at scala.meta.internal.parsers.ScalametaParser.expr(ScalametaParser.scala:1406)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$funDefRest$1(ScalametaParser.scala:2842)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.funDefRest(ScalametaParser.scala:2811)
	at scala.meta.internal.parsers.ScalametaParser.funDefOrDclOrSecondaryCtor(ScalametaParser.scala:2807)
	at scala.meta.internal.parsers.ScalametaParser.defOrDclOrSecondaryCtor(ScalametaParser.scala:2760)
	at scala.meta.internal.parsers.ScalametaParser.nonLocalDefOrDcl(ScalametaParser.scala:2748)
	at scala.meta.internal.parsers.ScalametaParser$$anonfun$templateStat$1.applyOrElse(ScalametaParser.scala:3287)
	at scala.meta.internal.parsers.ScalametaParser$$anonfun$templateStat$1.applyOrElse(ScalametaParser.scala:3283)
	at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
	at scala.meta.internal.parsers.ScalametaParser.statSeq(ScalametaParser.scala:3234)
	at scala.meta.internal.parsers.ScalametaParser.templateStats(ScalametaParser.scala:3282)
	at scala.meta.internal.parsers.ScalametaParser.templateStatSeq(ScalametaParser.scala:3279)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$templateBody$1(ScalametaParser.scala:3155)
	at scala.meta.internal.parsers.ScalametaParser.inBraces(ScalametaParser.scala:312)
	at scala.meta.internal.parsers.ScalametaParser.templateBody(ScalametaParser.scala:3155)
	at scala.meta.internal.parsers.ScalametaParser.templateBodyOpt(ScalametaParser.scala:3160)
	at scala.meta.internal.parsers.ScalametaParser.templateOpt(ScalametaParser.scala:3149)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$objectDef$1(ScalametaParser.scala:2934)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.objectDef(ScalametaParser.scala:2929)
	at scala.meta.internal.parsers.ScalametaParser.tmplDef(ScalametaParser.scala:2884)
	at scala.meta.internal.parsers.ScalametaParser.topLevelTmplDef(ScalametaParser.scala:2870)
	at scala.meta.internal.parsers.ScalametaParser$$anonfun$topStat$1.applyOrElse(ScalametaParser.scala:3253)
	at scala.meta.internal.parsers.ScalametaParser$$anonfun$topStat$1.applyOrElse(ScalametaParser.scala:3243)
	at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
	at scala.meta.internal.parsers.ScalametaParser.statSeq(ScalametaParser.scala:3234)
	at scala.meta.internal.parsers.ScalametaParser.topStatSeq(ScalametaParser.scala:3242)
	at scala.meta.internal.parsers.ScalametaParser.bracelessPackageStats$1(ScalametaParser.scala:3428)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$batchSource$9(ScalametaParser.scala:3434)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$batchSource$1(ScalametaParser.scala:3434)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.batchSource(ScalametaParser.scala:3406)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$source$1(ScalametaParser.scala:3389)
	at scala.meta.internal.parsers.ScalametaParser.atPos(ScalametaParser.scala:374)
	at scala.meta.internal.parsers.ScalametaParser.autoPos(ScalametaParser.scala:380)
	at scala.meta.internal.parsers.ScalametaParser.source(ScalametaParser.scala:3388)
	at scala.meta.internal.parsers.ScalametaParser.entrypointSource(ScalametaParser.scala:3394)
	at scala.meta.internal.parsers.ScalametaParser.$anonfun$parseSource$2(ScalametaParser.scala:128)
	at scala.meta.internal.parsers.ScalametaParser.parseRule(ScalametaParser.scala:38)
	at scala.meta.internal.parsers.ScalametaParser.parseSource(ScalametaParser.scala:128)
	at scala.meta.parsers.Parse$.$anonfun$parseSource$1(Parse.scala:29)
	at scala.meta.internal.parsers.ScalametaParser$$anon$189.apply(ScalametaParser.scala:3446)
	at scala.meta.parsers.Api$XtensionParseDialectInput.parse(Api.scala:21)
	at scala.meta.parsers.Api$XtensionParseInputLike.parse(Api.scala:10)
	at org.sonarsource.scala.converter.ScalaConverter.parse(ScalaConverter.scala:62)
	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:136)
	... 23 more
  • Scanner command used:

/Users/dmclean/javaLibraries/sonar-scanner-4.4.0.2170-macosx/bin/sonar-scanner -Dsonar.projectKey=aoix-grit -Dsonar.sources=. -Dsonar.host.url=https://plsonarq1.stsci.edu -Dsonar.login=4b3bb9255a344f069201a2d26b283580303a78e8 -Dsonar.java.binaries=**/build/classes/**/main

The error seems to be caused by the code it’s running against.

This command worked:

/Users/dmclean/javaLibraries/sonar-scanner-4.4.0.2170-macosx/bin/sonar-
scanner -Dsonar.projectKey=aoix-grit
-Dsonar.sources=/Users/dmclean/IdeaProjects/aoiGitLab02/laoi
-Dsonar.host.url=https://plsonarq1.stsci.edu
-Dsonar.login=4b3bb9255a344f069201a2d26b283580303a78e8
-Dsonar.java.binaries=.
-Dsonar.projectBaseDir=/Users/dmclean/IdeaProjects/aoiGitLab02/laoi

This command didn’t. The only difference is that it’s running against a different module of the same project:

/Users/dmclean/javaLibraries/sonar-scanner-4.4.0.2170-macosx/bin/sonar-
scanner -Dsonar.projectKey=aoix-grit
-Dsonar.sources=/Users/dmclean/IdeaProjects/aoiGitLab02/efl
-Dsonar.host.url=https://plsonarq1.stsci.edu
-Dsonar.login=4b3bb9255a344f069201a2d26b283580303a78e8
-Dsonar.java.binaries=.
-Dsonar.projectBaseDir=/Users/dmclean/IdeaProjects/aoiGitLab02/efl

Hello,

which version of Scala analyser are you using?
What changes between the commands is the different set of sources scanned so indeed it probably fails to analyse some particular file. Hence the scanner log snippet you shared does not consist of the line pointing to a file - can you try to identify it and exclude it from analysis? Does it succeed after that?

Kris

Hi Kris,

I couldn’t find any version reference specific to Scala, just the scanner version itself (4.4.0.2170). By temporarily deleting stuff, I was able to determine that the problem is specific to a set of four functions from a single class. Using sonar.excluded, I was able to exclude that file and everything else gets analyzed.

I don’t see anything particularly odd about those four functions, and I would like to get the rest of the file analyzed.

The code in question:

  def updateCriteria(sortCriteria: Array[(String, Boolean)], column: String, index: Int): Array[(String, Boolean)] = {
    if (index >= sortCriteria.length) addColumn(sortCriteria, column)
    else if (column == sortCriteria(index)._1) updateColumn(sortCriteria, index)
    else replaceColumn(sortCriteria, column, index)
  }

  private def addColumn(sortCriteria: Array[(String, Boolean)], column: String): Array[(String, Boolean)] = {
    val result = new Array[(String, Boolean)](sortCriteria.length + 1)
    Array.copy(sortCriteria, 0, result, 0, sortCriteria.length)
    result(sortCriteria.length) = new (String, Boolean)(column, true)
    result
  }

  private def updateColumn(sortCriteria: Array[(String, Boolean)], index: Int): Array[(String, Boolean)] = {
    val result = new Array[(String, Boolean)](sortCriteria.length)
    Array.copy(sortCriteria, 0, result, 0, sortCriteria.length)
    result(index) = new (String, Boolean)(result(index)._1, !result(index)._2)
    result
  }

  private def replaceColumn(sortCriteria: Array[(String, Boolean)], column: String, index: Int): Array[(String, Boolean)] = {
    val result = new Array[(String, Boolean)](index + 1)
    Array.copy(sortCriteria, 0, result, 0, index)
    result(index) = new (String, Boolean)(column, true)
    result
  }

Expressions like new (String, Boolean)("str", true) seem to crash the underlying Scalameta parser, probably because it is not expecting to see a tuple type (String, Boolean) in the position of a constructor. I assume that most people reading this code would also not expect to see new (String, Boolean)("str", true) instead of just ("str", true).

If you replace all new (String, Boolean)(str, bln) by just the tuples (str, bln), it should get through Scalameta, and the problem should go away.

Out of curiosity: was the code generated through some automatic translation tool?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.