From d686957d8241027748a938225b8aa3dab0eb2e52 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 16 Jul 2024 12:36:26 +0200 Subject: [PATCH] fix(cyclonedx): Avoid a NPE when clearing `extensibleTypes` This is a fixup for 023dfb6 which started to conditionally set the `LicenseChoice`. If the condition is not met and `licenses` is `null`, do not try to clear `extensibleTypes` from them. Signed-off-by: Sebastian Schuberth --- .../cyclonedx/src/main/kotlin/CycloneDxReporter.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt index 6102553300dda..51b2eb2488bb3 100644 --- a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt +++ b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt @@ -406,13 +406,15 @@ private fun generateBom(bom: Bom, schemaVersion: Version, fileExtension: String) // Clear the "dependencyType". component.extensibleTypes = null - component.licenses.licenses.forEach { license -> - // Clear the "origin". - license.extensibleTypes = null - } + if (component.licenses?.licenses != null) { + component.licenses.licenses.forEach { license -> + // Clear the "origin". + license.extensibleTypes = null + } - // Remove duplicates that may occur due to clearing the distinguishing extensive type. - component.licenses.licenses = component.licenses.licenses.distinct() + // Remove duplicates that may occur due to clearing the distinguishing extensive type. + component.licenses.licenses = component.licenses.licenses.distinct() + } } }