CycloneDX / CycloneDX/cyclonedx-cli
'Object reference not set to an instance of an object' error when trying to convert BOM without components
- Dominant language
- C#
- Stars
- 541
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Description
Currently, `cyclonedx-linux-x64 convert` crashes with `Object reference not set to an instance of an object` when a BOM has no components:
```
cyclonedx-linux-x64 convert --input-file target/maven.bom.xml --output-format csv
Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
at CycloneDX.Cli.Serialization.CsvSerializer.Serialize(Bom bom)
at CycloneDX.Cli.CliUtils.OutputBomHelper(Bom bom, ConvertFormat format, Nullable`1 outputVersion, String filename)
at CycloneDX.Cli.Commands.ConvertCommand.Convert(ConvertCommandOptions options)
at System.CommandLine.Invocation.CommandHandler.GetExitCodeAsync(Object value, InvocationContext context)
at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<b__1>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<b__0>d.MoveNext()
```
I think the issue is in [`CsvSerializer`](https://github.com/CycloneDX/cyclonedx-cli/blob/5de8d19b2b678da8a04bd6dba38cdae26ef4347f/src/cyclonedx/Serialization/CsvSerializer.cs#L74):
```
foreach (var c in bom.Components)
```
Presumably, `bom.Components` is not set when the BOM has no components.
Contributor guide
Assessment
This issue has not been assessed yet.