Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-9489

Scanner fails on SonarCloud when deactivating a rule from a profile

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 6.5-M1
    • Fix Version/s: 6.5-M3, 6.5
    • Component/s: Quality Profile
    • Labels:

      Description

      Scanners fail on SonarCloud when a rule has been deactivated from a Quality profile. Scanner error is:

      22:10:19 INFO: Load quality profiles
      22:10:19 INFO: Load quality profiles (done) | time=16ms
      22:10:19 INFO: Load active rules
      22:10:19 INFO: ------------------------------------------------------------------------
      22:10:19 INFO: EXECUTION FAILURE
      22:10:19 INFO: ------------------------------------------------------------------------
      22:10:19 INFO: Total time: 2.236s
      22:10:19 INFO: Final Memory: 42M/101M
      22:10:19 INFO: ------------------------------------------------------------------------
      22:10:19 ERROR: Error during SonarQube Scanner execution
      22:10:19 java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.report.ActiveRulesPublisher
      22:10:19 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:71)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:621)
      22:10:19 	at org.picocontainer.parameters.CollectionComponentParameter.getArrayInstance(CollectionComponentParameter.java:334)
      22:10:19 	at org.picocontainer.parameters.CollectionComponentParameter.access$100(CollectionComponentParameter.java:49)
      22:10:19 	at org.picocontainer.parameters.CollectionComponentParameter$1.resolveInstance(CollectionComponentParameter.java:139)
      22:10:19 	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:141)
      22:10:19 	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
      22:10:19 	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
      22:10:19 	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
      22:10:19 	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
      22:10:19 	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
      22:10:19 	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
      22:10:19 	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
      22:10:19 	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1034)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1026)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1003)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
      22:10:19 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
      22:10:19 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
      22:10:19 	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
      22:10:19 	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
      22:10:19 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
      22:10:19 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
      22:10:19 	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
      22:10:19 	at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
      22:10:19 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
      22:10:19 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      22:10:19 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      22:10:19 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      22:10:19 	at java.lang.reflect.Method.invoke(Method.java:498)
      22:10:19 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
      22:10:19 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
      22:10:19 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
      22:10:19 	at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
      22:10:19 	at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
      22:10:19 	at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
      22:10:19 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
      22:10:19 Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.api.batch.rule.ActiveRules
      22:10:19 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:71)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
      22:10:19 	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
      22:10:19 	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
      22:10:19 	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
      22:10:19 	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
      22:10:19 	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
      22:10:19 	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
      22:10:19 	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
      22:10:19 	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
      22:10:19 	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
      22:10:19 	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
      22:10:19 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:69)
      22:10:19 	... 37 more
      22:10:19 Caused by: java.lang.NullPointerException
      22:10:19 	at org.sonar.scanner.rule.DefaultActiveRulesLoader.readPage(DefaultActiveRulesLoader.java:102)
      22:10:19 	at org.sonar.scanner.rule.DefaultActiveRulesLoader.load(DefaultActiveRulesLoader.java:62)
      22:10:19 	at org.sonar.scanner.rule.ActiveRulesProvider.load(ActiveRulesProvider.java:98)
      22:10:19 	at org.sonar.scanner.rule.ActiveRulesProvider.load(ActiveRulesProvider.java:61)
      22:10:19 	at org.sonar.scanner.rule.ActiveRulesProvider.provide(ActiveRulesProvider.java:48)
      22:10:19 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      22:10:19 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      22:10:19 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      22:10:19 	at java.lang.reflect.Method.invoke(Method.java:498)
      22:10:19 	at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
      22:10:19 	at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39)
      22:10:19 	at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113)
      22:10:19 	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
      22:10:19 	at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
      22:10:19 	at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
      22:10:19 	at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
      22:10:19 	at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
      22:10:19 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
      22:10:19 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:69)
      22:10:19 	... 51 more
      22:10:19 ERROR: 
      22:10:19 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
      

      The deactivation is badly taken into account and leads to unexpected behavior in the Quality profiles administration page (see attached screenshot).

      Explanation

      Scanner fails because the web service /api/rules/search?f=repo,actives&activation=true&qprofile=xxx returns "rules" without associated "actives":

      {
        "total": 2,
        "p": 1,
        "ps": 500,
        "rules": [
          {
            "key": "c:S872"
          },
          {
            "key": "c:S1836",
          }
        ], "actives": {
          "c:S872": [
            {
              "qProfile": "AVzoyrRygIkbjTX1x7V7",
              "inherit": "NONE",
              "severity": "MAJOR",
              "params": [],
              "createdAt": "2017-06-27T11:03:40+0200"
            }
           // BUG: missing object with key "c:S1836"
          ]
      

      The root cause is that multiple shards have been enabled on SonarCloud for the index rules. As parent/child relationships are used between rules and active rules, the routing value has to be fixed when indexing and deleting documents, otherwise search results are not consistent. It is not, routing is missing.
      Note that error does not exist in the standard distribution because a single shard is used by default. All documents are stored in the same shard and parent/child relationships can always be resolved.

      Workarounds

      A workaround for users is to copy the profile to another one. Corrupted rules won't be copied.
      A workaround for infra team is to reset the number of shards of rules index to 1.

      Notes

      To prevent any further similar errors on index types with parent/child relationships:

      • multiple shards should be used by QA tests, or default number of shards should always be 2 or greater
      • the routing attribute should be enforced on index/delete operations by setting the property _routing to required: true (see https://www.elastic.co/blog/customizing-your-document-routing). Note that it does not seem to work correctly with Elasticsearch 2.4.4. Upgrading to version 5.x could help (SONAR-8798).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                simon.brandhof Simon Brandhof
                Reporter:
                simon.brandhof Simon Brandhof
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: