Duplicate key message

  • IntelliJ IDEA 2020.2; SonarLint 6.5.1.43866

  • I am trying to install & configure SonarLint via Server. I followed below steps but getting errors.

  • In IntelliJ IDEA, I went to File > Settings > Tools > SonarLint > Project Settings > Selected CheckBox for Bind project to SonarQube/SonarCloud > Created a new connection with Token > Clicked on Update binding > Got below error message.

  • Error
    Server started on 64120
    Plugin ‘secrets’ embeds dependencies. This will be deprecated soon. Plugin should be updated.
    Plugin ‘swift’ embeds dependencies. This will be deprecated soon. Plugin should be updated.
    Sync quality profiles…
    Downloaded plugin list in 54ms
    [SYNC] Synchronizing analyzer configuration for project ‘com.mycompanyname’
    Downloaded settings in 52ms
    [SYNC] Fetching rule set for ‘java’
    [SYNC] Fetching rule set for ‘js’
    [SYNC] Fetching rule set for ‘kotlin’
    [SYNC] Fetching rule set for ‘php’
    [SYNC] Fetching rule set for ‘py’
    [SYNC] Fetching rule set for ‘ruby’
    [SYNC] Fetching rule set for ‘scala’
    [SYNC] Fetching rule set for ‘swift’
    [SYNC] Fetching rule set for ‘ts’
    [SYNC] Fetching rule set for ‘web’
    [SYNC] Fetching rule set for ‘xml’
    Error updating the storage for connection ‘TestSonarQube1’
    java.lang.IllegalStateException: Duplicate key message (attempted merging values Spring component-scan element has an invalid base-package attribute value and Spring component-scan element has an invalid base-package attribute value)
    at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:133)
    at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:180)
    at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)

Hello @ppat7046,

Thanks for raising this. By any chance would you have a more complete stacktrace ? This one looks truncated. Also could you check if there are some third-party plugins installed on the server ?

Was anything ever done about this? I’m getting the same exact error in IntelliJ IDEA 2021.3.1 with the IntelliJ Sonarlint Plugin 6.8.0.50884 and SonarQube server 8.9.6 (build 50800). Spring Tools Suite 3.7.2 with SonarLint for Eclipse 3.5.0.201804241315 works fine.

[SYNC] Synchronizing analyzer configuration for project 'com.vanguard.retail:personal-performance.webservice'
Downloaded settings in 54ms
[SYNC] Fetching rule set for language 'java' from profile 'java-enterprise-current-59904'
[SYNC] Fetching rule set for language 'js' from profile 'js-enterprise-current-55112'
[SYNC] Fetching rule set for language 'kotlin' from profile 'AXTWyvM1xKV3NS3SPowg'
[SYNC] Fetching rule set for language 'php' from profile 'AWhzVQCXzbRDzf2BayC8'
[SYNC] Fetching rule set for language 'py' from profile 'AWhzVOaXzbRDzf2Bawc5'
[SYNC] Fetching rule set for language 'ruby' from profile 'AX3kNduYejKLgsAUozKk'
[SYNC] Fetching rule set for language 'scala' from profile 'scala-retail-rdna-rules-59187'
[SYNC] Fetching rule set for language 'swift' from profile 'AWhzVPmDzbRDzf2BaxqC'
[SYNC] Fetching rule set for language 'ts' from profile 'AW1oap_f2AqgPRiH4Iy2'
[SYNC] Fetching rule set for language 'web' from profile 'web-enterprise-current-78910'
[SYNC] Fetching rule set for language 'xml' from profile 'xml-enterprise-current-32055'
Error updating the storage for connection 'personal-performance.webservice'
java.lang.IllegalStateException: Duplicate key message (attempted merging values Spring component-scan element has an invalid base-package attribute value and Spring component-scan element has an invalid base-package attribute value)
  at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:133)
  at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:180)
  at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
  at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
  at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
  at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
  at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
  at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
  at org.sonarsource.sonarlint.core.serverapi.rules.RulesApi.getAllActiveRules(RulesApi.java:78)
  at org.sonarsource.sonarlint.core.storage.LocalStorageSynchronizer.toRuleSet(LocalStorageSynchronizer.java:80)
  at org.sonarsource.sonarlint.core.storage.LocalStorageSynchronizer.lambda$synchronizeAnalyzerConfig$3(LocalStorageSynchronizer.java:71)
  at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:178)
  at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
  at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
  at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
  at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
  at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
  at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
  at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
  at org.sonarsource.sonarlint.core.storage.LocalStorageSynchronizer.synchronizeAnalyzerConfig(LocalStorageSynchronizer.java:71)
  at org.sonarsource.sonarlint.core.storage.LocalStorageSynchronizer.lambda$synchronize$0(LocalStorageSynchronizer.java:57)
  at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:178)
  at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
  at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1621)
  at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
  at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
  at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
  at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
  at org.sonarsource.sonarlint.core.storage.LocalStorageSynchronizer.synchronize(LocalStorageSynchronizer.java:57)
  at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.sync(ConnectedSonarLintEngineImpl.java:368)
  at org.sonarlint.intellij.tasks.BindingStorageUpdateTask.tryUpdateProjectStorages(BindingStorageUpdateTask.java:176)
  at org.sonarlint.intellij.tasks.BindingStorageUpdateTask.updateProjectStorages(BindingStorageUpdateTask.java:133)
  at org.sonarlint.intellij.tasks.BindingStorageUpdateTask.run(BindingStorageUpdateTask.java:109)
  at org.sonarlint.intellij.tasks.BindingStorageUpdateTask$2.run(BindingStorageUpdateTask.java:90)
  at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:436)
  at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:120)
  at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsync$5(CoreProgressManager.java:496)
  at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:244)
  at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:188)
  at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:624)
  at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:698)
  at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:646)
  at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:623)
  at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:66)
  at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:175)
  at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:244)
  at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
  at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
  at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
  at java.base/java.security.AccessController.doPrivileged(Native Method)
  at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
  at java.base/java.lang.Thread.run(Thread.java:829)

I had to revert all the way back to IntelliJ Sonarlint plugin version 6.3.1.40498, to get the error to go away and binding to work. 6.4.0.41939 and newer throw that error.

Unfortunately even though the error went away, Sonarlint didn’t properly analyze currently open files on the fly. I made a change that caused STS to report a Sonar error, but IntelliJ said there were no open files with errors. It did analyze all files.

Edit: On the fly SonarLint does work, just not for all rules. Basically though any version of the IntelliJ plugin 6.4.0.41939 and newer doesn’t work.

Hello @Morac,

Thanks for bringing more details to this topic. I would be interested to get the result of those 2 API calls on your SonarQube (from a browser would be enough):

  • api/plugins/installed
  • api/rules/search?qprofile=xml-enterprise-current-32055&activation=true&f=templateKey,actives&types=CODE_SMELL,BUG,VULNERABILITY&s=key

Could you upload 2 files with the results here please ?

I’m blocked from uploading files. Is there something specific you are looking for in those responses?
In the meantime, based on the stack trace error message, it looks like the plugin doesn’t like the fact that there are multiple “Spring component-scan element has an invalid base-package attribute value” values. Instead erroring on a duplicate value, the plugin should probably just ignore the duplicate.

    "actives": {
        "xml:Invalid_Spring_Component_Scan_Base_Package_Check": [{
                "qProfile": "xml-enterprise-current-32055",
                "inherit": "NONE",
                "severity": "INFO",
                "params": [{
                        "key": "message",
                        "value": "Spring component-scan element has an invalid base-package attribute value"
                    }, {
                        "key": "message",
                        "value": "Spring component-scan element has an invalid base-package attribute value"
                    }, {
                        "key": "expression",
                        "value": "//beans/component-scan[normalize-space(@base-package)\u003d\"PACKAGE NAME OF THE SERVICE OBJECTS\"]"
                    }, {
                        "key": "expression",
                        "value": "//beans/component-scan[normalize-space(@base-package)\u003d\"PACKAGE NAME OF THE SERVICE OBJECTS\"]"
                    }, {
                        "key": "filePattern",
                        "value": "**/spring-*.xml"
                    }, {
                        "key": "filePattern",
                        "value": "**/spring-*.xml"
                    }, {
                        "key": "filePattern",
                        "value": "**/spring-*.xml"
                    }, {
                        "key": "expression",
                        "value": "//beans/component-scan[normalize-space(@base-package)\u003d\"PACKAGE NAME OF THE SERVICE OBJECTS\"]"
                    }, {
                        "key": "message",
                        "value": "Spring component-scan element has an invalid base-package attribute value"
                    }
                ],
                "createdAt": "2016-03-02T14:01:47+0000",
                "updatedAt": "2016-03-02T14:01:47+0000"
            }
        ],

Hello Michael,

Those fields are not supposed to be duplicated. Before changing anything on SonarLint side, I want to understand what happened. What appears on this rule page in the UI ? You can find it through your XML Quality Profile