Error in building maven project with GraalVM whose dependency is on sonarlint-core

Hi all,

First of all, sorry for putting inaccurate tags on this issue. My question is related to using SonarSource maven packages in java applications instead of using standalone SonarSource projects like - sonarlint, etc. And I could not find a relevant tag for it.

I am trying to build my java application, which is dependent upon org.sonarsource.sonarlint.core::sonarlint-core@8.6.0.47852, using native-maven-plugin so that I can get a native executable out of it. The build process succeeds, but when I try to execute the executable generated, I get the following error.

Exception in thread "main" java.lang.ExceptionInInitializerError
        at sorald.sonar.SonarRuleRepository.getAllRules(SonarRuleRepository.java:25)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.util.ServiceLoader$ProviderSpliterator.tryAdvance(ServiceLoader.java:1492)
        at java.util.Spliterator.forEachRemaining(Spliterator.java:326)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
        at sorald.rule.RuleProvider.getAllRules(RuleProvider.java:26)
        at sorald.rule.RuleProvider.inferRules(RuleProvider.java:100)
        at sorald.cli.MineCommand.call(MineCommand.java:97)
        at sorald.cli.MineCommand.call(MineCommand.java:25)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at sorald.Main.main(Main.java:7)
Caused by: java.lang.IllegalStateException: Unable to extract rules metadata
        at org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractor.extractRules(RulesDefinitionExtractor.java:40)
        at org.sonarsource.sonarlint.core.AbstractSonarLintEngine.loadPluginMetadata(AbstractSonarLintEngine.java:77)
        at sorald.sonar.SonarLintEngine.computeAllRulesDefinitionsByKey(SonarLintEngine.java:132)
        at sorald.sonar.SonarLintEngine.<clinit>(SonarLintEngine.java:57)
        ... 23 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonarsource.sonarlint.core.rule.extractor.RuleDefinitionsLoader
        at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:57)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
        at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer.getComponentByType(ComponentContainer.java:249)
        at org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractorContainer.doAfterStart(RulesDefinitionExtractorContainer.java:79)
        at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer.startComponents(ComponentContainer.java:119)
        at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer.execute(ComponentContainer.java:104)
        at org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractor.extractRules(RulesDefinitionExtractor.java:37)
        ... 26 more
Caused by: org.sonarsource.sonarlint.shaded.org.picocontainer.PicoCompositionException: Either the specified parameters do not match any of the following constructors: []; OR the constructors were not accessible for 'org.sonarsource.sonarlint.core.rule.extractor.RuleDefinitionsLoader'
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:200)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:110)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector.access$100(ConstructorInjector.java:51)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:331)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
        at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
        at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:55)
        ... 32 more

Initially, I was getting a different error because GraalVM needs to know all the resources used during compile time so I passed the following config file to the build process:

{
  "resources": {
    "includes": [
      {"pattern": "plugins_min_versions.txt$"},
      {"pattern":  "sonarlint-api-version.txt$"},
      {"pattern":  "sonar-api-version.txt$"}
    ]
  }
}

Can anyone please help me figure out what exactly is going wrong? Please note that exception is thrown at runtime when executable is built with GraalVM. But it works well when I build the jar using JVM provided by openjdk-11.

Hi @aman

We have not yet started to look at GraalVM (but this is on our radar) so I’m afraid we won’t be able to help you here since we have no experience with it.

Thanks for replying, Julien ! Glad to hear that it’s on the team’s radar.