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

Rule parameters can be duplicated in database

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.2
    • Component/s: Database, Rules
    • Labels:
      None

      Description

      Initial thread: https://github.com/SonarSource/SonarJS/issues/971

      Database may contain multiple times the same rule parameter. That makes server startup fail if the rule is activated in a built-in Quality profile.
      Error is:

      2018.05.08 11:07:59 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile py/Sonar way
      2018.05.08 11:07:59 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
      java.lang.IllegalArgumentException: Duplicate key format
      	at org.sonar.core.util.stream.MoreCollectors.putAndFailOnDuplicateKey(MoreCollectors.java:295)
      	at org.sonar.core.util.stream.MoreCollectors.lambda$uniqueIndex$9(MoreCollectors.java:256)
      	at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
      	at java.util.Iterator.forEachRemaining(Iterator.java:116)
      	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
      	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
      	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
      	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
      	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
      	at org.sonar.server.qualityprofile.RuleActivationContext$RuleWrapper.<init>(RuleActivationContext.java:282)
      	at org.sonar.server.qualityprofile.RuleActivationContext$RuleWrapper.<init>(RuleActivationContext.java:276)
      	at org.sonar.server.qualityprofile.RuleActivationContext.<init>(RuleActivationContext.java:90)
      	at org.sonar.server.qualityprofile.RuleActivationContext.<init>(RuleActivationContext.java:55)
      	at org.sonar.server.qualityprofile.RuleActivationContext$Builder.build(RuleActivationContext.java:272)
      	at org.sonar.server.qualityprofile.RuleActivator.createContextForBuiltInProfile(RuleActivator.java:381)
      	at org.sonar.server.qualityprofile.BuiltInQProfileUpdateImpl.update(BuiltInQProfileUpdateImpl.java:61)
      	at org.sonar.server.qualityprofile.RegisterQualityProfiles.update(RegisterQualityProfiles.java:118)
      	at org.sonar.server.qualityprofile.RegisterQualityProfiles.lambda$start$1(RegisterQualityProfiles.java:85)
      	at java.lang.Iterable.forEach(Iterable.java:75)
      	at org.sonar.server.qualityprofile.RegisterQualityProfiles.start(RegisterQualityProfiles.java:80)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
      	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
      	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
      	at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
      	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
      	at org.picocontainer.behaviors.Stored.start(Stored.java:110)
      	at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
      	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
      	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
      	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:134)
      	at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
      	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:44)
      	at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:81)
      	at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:45)
      	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:78)
      	at org.sonar.server.platform.Platform.executeStartupTasks(Platform.java:196)
      	at org.sonar.server.platform.Platform.access$400(Platform.java:46)
      	at org.sonar.server.platform.Platform$1.lambda$doRun$1(Platform.java:121)
      	at org.sonar.server.platform.Platform$AutoStarterRunnable.runIfNotAborted(Platform.java:371)
      	at org.sonar.server.platform.Platform$1.doRun(Platform.java:121)
      	at org.sonar.server.platform.Platform$AutoStarterRunnable.run(Platform.java:355)
      	at java.lang.Thread.run(Thread.java:748)
      

      The solution consists of:

      • adding the missing unique index on columns [ rule_id, name ] of db table rules_parameters
      • fixes the bug in the persistence of rule parameters at server startup, if still exists.

      The workaround is to drop the duplicated rows in table rules_parameters:

      SELECT rule_id, name, count(name)
      FROM public.rules_parameters
      group by rule_id, name
      having count(name)>1
      

      A single row should be kept for each couple rule_id / name.

        Attachments

          Activity

            People

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

              Dates

              • Due:
                Created:
                Updated:
                Resolved: