Missing blob jgit error with SonarCloud

We are using .NET C# and CircleCI. Our build pipeline worked without any issues for quite a long time.
However recently it started failing test step with a very weird error:

ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: org.eclipse.jgit.errors.MissingObjectException: Missing blob 14334bea9ef277dd309f82450e7317a1b204cedd
        at org.sonar.scm.git.blame.FileBlamer.waitForTasks(FileBlamer.java:238)
        at org.sonar.scm.git.blame.FileBlamer.blameWithFileDiffs(FileBlamer.java:213)
        at org.sonar.scm.git.blame.FileBlamer.blameParent(FileBlamer.java:133)
        at org.sonar.scm.git.blame.BlameGenerator.process(BlameGenerator.java:149)
        at org.sonar.scm.git.blame.BlameGenerator.generateBlame(BlameGenerator.java:127)
        at org.sonar.scm.git.blame.RepositoryBlameCommand.call(RepositoryBlameCommand.java:123)
        at org.sonar.scm.git.CompositeBlameCommand.blameWithFilesGitCommand(CompositeBlameCommand.java:187)
        at org.sonar.scm.git.CompositeBlameCommand.blame(CompositeBlameCommand.java:84)
        at org.sonar.scanner.scm.ScmPublisher.publish(ScmPublisher.java:76)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:164)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
        at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:397)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:125)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:57)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:51)
        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:568)
        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)

This error is preventing us from using SonarCloud for the affected project. Only 1 project is affected, but on multiple branches. There are a lot of commits in this repository. Some branches just build without any issues.

This is the commands we are using for test + sonar:

        apt-get update && apt-get install libunwind8 libxml2 -y
        dotnet sonarscanner begin /k:"<<parameters.sonarscanner_project_key>>" /d:sonar.login=$SONAR_TOKEN /d:sonar.host.url=https://sonarcloud.io /o:"someorgname" /d:sonar.verbose=false /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" /d:sonar.coverage.exclusions="**Tests*.cs,**/Migrations/*.cs,**/Startup.cs,**Program.cs,**Startup.cs"
        dotnet build
        dotnet test --logger "trx" --logger "console;verbosity=detailed" --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.SplitCoverage="True" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
        dotnet sonarscanner end /d:sonar.login=$SONAR_TOKEN

Can you please suggest what can cause this issue and some potential fix?
Thank you.

Hi @IvanSimanenka

Can you confirm you have blobless clone enabled in your pipeline?

Hello Julien.
We are using standard circleci checkout command (CircleCI configuration reference) which does not support any parameters.
Modifying it to something custom is a very tricky thing.

Had a similar experience with CircleCI recently. Yes, their checkout command is now doing blob less clones.

See CircleCI Developer Hub - guitarrapc/git-shallow-clone for a workaround. If you use the checkout_advanced command you can control the number of commits or even simpler bring everything by just passing -v so that the default depth is overriden

I am encountering a similar problem. Our pipeline was working just fine until a few weeks ago, but now we are getting the same error.

@Julien_HENRY we also use the checkout command in CircleCI which is confirmed to be a blobless clone as you stated. I posted in CircleCI letting them know that this is affect sonar here: [Product Update] Speeding up code checkout - #8 by brettjohnsen-sy - Build Environment - CircleCI Discuss

I don’t have CircleCI to test, but you can possibly use:

- checkout
- run: git fetch --no-filter --refetch

to fetch the entire history before running the SonarQube analysis.

I was able to fix the issue following the suggestion from Jose Javier Señaris.
This is how my checkout step looks now:

  - git-shallow-clone/checkout_advanced:
      clone_options: '--filter=blob:none'

With the usage of orb guitarrapc/git-shallow-clone.

We are getting the same error:

13:09:12.629 ERROR Error during SonarScanner Engine execution
java.lang.IllegalStateException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: org.eclipse.jgit.errors.MissingObjectException: Missing blob 9c39500c6c3c351940bb84d646710d28acdfcfd4
at org.sonar.scm.git.blame.FileBlamer.waitForTasks(FileBlamer.java:238)
at org.sonar.scm.git.blame.FileBlamer.blameWithFileDiffs(FileBlamer.java:213)
at org.sonar.scm.git.blame.FileBlamer.blameParent(FileBlamer.java:133)
at org.sonar.scm.git.blame.BlameGenerator.process(BlameGenerator.java:149)
at org.sonar.scm.git.blame.BlameGenerator.generateBlame(BlameGenerator.java:127)
at org.sonar.scm.git.blame.RepositoryBlameCommand.call(RepositoryBlameCommand.java:123)
at org.sonar.scm.git.CompositeBlameCommand.blameWithFilesGitCommand(CompositeBlameCommand.java:203)
at org.sonar.scm.git.CompositeBlameCommand.blame(CompositeBlameCommand.java:100)
at org.sonar.scanner.scm.ScmPublisher.execute(ScmPublisher.java:101)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
at java.base/java.util.ArrayList$ArrayListSpliterator.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.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.forEach(Unknown Source)
at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:168)
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:210)
at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:189)
at org.sonar.scanner.bootstrap.SpringScannerContainer.doAfterStart(SpringScannerContainer.java:465)
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:210)
at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:189)
at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:146)
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:210)
at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:189)
at org.sonar.scanner.bootstrap.ScannerMain.runScannerEngine(ScannerMain.java:143)
at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:58)
at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:42)
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: org.eclipse.jgit.errors.MissingObjectException: Missing blob 9c39500c6c3c351940bb84d646710d28acdfcfd4
at java.base/java.util.concurrent.FutureTask.report(Unknown Source)
at java.base/java.util.concurrent.FutureTask.get(Unknown Source)
at org.sonar.scm.git.blame.FileBlamer.waitForTasks(FileBlamer.java:232)
… 29 common frames omitted
Caused by: java.lang.IllegalStateException: org.eclipse.jgit.errors.MissingObjectException: Missing blob 9c39500c6c3c351940bb84d646710d28acdfcfd4
at org.sonar.scm.git.blame.BlobReader.loadText(BlobReader.java:63)
at org.sonar.scm.git.blame.FileBlamer.splitBlameWithParent(FileBlamer.java:258)
at org.sonar.scm.git.blame.FileBlamer.lambda$blameWithFileDiffs$0(FileBlamer.java:202)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing blob 9c39500c6c3c351940bb84d646710d28acdfcfd4
at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:138)
at org.sonar.scm.git.blame.BlobReader.loadText(BlobReader.java:69)
at org.sonar.scm.git.blame.BlobReader.loadText(BlobReader.java:60)
… 6 common frames omitted

We are using CircleCI and we might be affected by their recent gradual move of all customers to blobless git clone.

However we have modified our pipeline to do a --no–filter clone and we are still experiencing the issue.

Moreover ater we see the error we ssh into the build instance and we can see that the blob actually exists.

git cat-file -t 9c39500c6c3c351940bb84d646710d28acdfcfd4
remote: Enumerating objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 1 (from 1)
Receiving objects: 100% (1/1), 864 bytes | 864.00 KiB/s, done.
blob

We’ve ended up doing the checkout like this:

  - git-shallow-clone/checkout_advanced:
      clone_options: '--filter=blob:none'
  - run:
      name: "Git fetch"
      command: git fetch --no-filter --refetch

Works like a charm for us.