Bug: duplicate key with different file casing (sonar scanner .NET)

Description

After changing some file names in our repo we run into the issue below. This happened after we changed just the casing of some filenames due to cross-build issue we had. It looks like the dotnet scanner on windows has issues due to case sensitivity and breaks.

This issue only happens with PR analysis and doesn’t happen with a single branch analysis.

java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectFileIndexer
	at org.sonar.core.platform.SpringComponentContainer.getComponentByType(SpringComponentContainer.java:139)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:3[63](https://github.com/org/automationl/actions/runs/4304271659/jobs/7505992173#step:11:64))
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:137)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:[66](https://github.com/org/automation/actions/runs/4304271659/jobs/7505992173#step:11:67))
	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(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:5[68](https://github.com/org/automation/actions/runs/4304271659/jobs/7505992173#step:11:69))
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$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:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@59309333-org.sonar.scanner.scan.filesystem.ProjectFileIndexer': Unsatisfied dependency expressed through constructor parameter 7; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@59309333-org.sonar.scanner.scan.filesystem.FileIndexer': Unsatisfied dependency expressed through constructor parameter 6; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@59309333-org.sonar.scanner.scan.filesystem.MetadataGenerator': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@59309333-org.sonar.scanner.scan.filesystem.StatusDetection': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ScmChangedFiles' defined in org.sonar.scanner.scm.ScmChangedFilesProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sonar.scanner.scm.ScmChangedFiles]: Factory method 'provide' threw exception; nested exception is java.lang.IllegalStateException: Duplicate key D:\actions-runner\_work\automation\automationConfigMgnt\ConfigMgnt.Tests\TestServiceCollectionExtensions.cs (attempted merging values org.sonar.scm.git.ChangedFile@eebd3ba5 and org.sonar.scm.git.ChangedFile@eebd3ba5)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:13[72](https://github.com/org/automation/actions/runs/4304271659/jobs/7505992173#step:11:73))
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:5[82](https://github.com/org/automation/actions/runs/4304271659/jobs/7505992173#step:11:83))
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:12[84](https://github.com/org/automation/actions/runs/4304271659/jobs/7505992173#step:11:85))
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1245)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:4[94](https://github.com/org/automation/actions/runs/4304271659/jobs/7505992173#step:11:95))
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1172)
	at org.sonar.core.platform.SpringComponentContainer.getComponentByType(SpringComponentContainer.java:137)
	... 20 more

Repro steps

Change the casing of a file in a new branch and run a PR analysis between the the two branches with the file with the different casing.

Known workarounds

no known workaround

Related information

  • C#/VB.NET Plugins version C# 10
  • Visual Studio version 2022
  • MSBuild / dotnet version 6.0
  • SonarScanner for .NET version (if used) 5.11
  • Operating System Windows Server 2022

Hey there.

What version of SonarQube are you using?

SonarQube 9.9

Hi @OneCyrus
Thanks a lot for the report

We have identified an issue in the case of a file rename involving only changing the case on Windows.
I have created a ticket on our side

I think the issue still exists in version 10.6 if the renaming was not in the filename but somewhere in the path.

Caused by: java.lang.IllegalStateException: Duplicate key C:\GitlabRunner\builds\1kBhiSWj\0\software\production\production_platform\prodtool\src\APS.Production.UI.Devices\controls\n62\N62StatusView.xaml (attempted merging values org.sonar.scm.git.ChangedFile@2ddfb1d0 and org.sonar.scm.git.ChangedFile@d0dc0ccc) at java.base/java.util.stream.Collectors.duplicateKeyException(Unknown Source) at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Unknown Source) at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(Unknown Source) at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(Unknown Source) at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source) at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source) at org.sonar.scanner.scm.ScmChangedFiles.lambda$toChangedFilesByPathMap$0(ScmChangedFiles.java:78) at java.base/java.util.Optional.map(Unknown Source) at org.sonar.scanner.scm.ScmChangedFiles.toChangedFilesByPathMap(ScmChangedFiles.java:78) at org.sonar.scanner.scm.ScmChangedFiles.<init>(ScmChangedFiles.java:44) at org.sonar.scanner.scm.ScmChangedFilesProvider.provide(ScmChangedFilesProvider.java:53) 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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)

Hello @stefan.leichle,
We are not able to reproduce the issue by changing the case of a directory in the path.
Could you give us more details about your use case? What operations did you do exactly?
Thanks