diff --git a/pkg/sbom/io/encode.go b/pkg/sbom/io/encode.go index 590935bb3dba..87fbe2ef96fc 100644 --- a/pkg/sbom/io/encode.go +++ b/pkg/sbom/io/encode.go @@ -85,11 +85,9 @@ func (e *Encoder) rootComponent(r types.Report) (*core.Component, error) { root.Type = core.TypeRepository case artifact.TypeCycloneDX, artifact.TypeSPDX: // When we scan SBOM file - if r.BOM != nil { - // If SBOM file doesn't contain root component - use filesystem - if bomRoot := r.BOM.Root(); bomRoot != nil { - return bomRoot, nil - } + // If SBOM file doesn't contain root component - use filesystem + if r.BOM != nil && r.BOM.Root() != nil { + return r.BOM.Root(), nil } // When we scan a `json` file (meaning a file in `json` format) which was created from the SBOM file. // e.g. for use in `convert` mode.