Skip to content

Commit 78fb251

Browse files
heliocastromnonnenmacher
authored andcommitted
fix(python-inspector): Null check for purl before mapping it
With the introduction of commit 0b9fa5b, null purl's output given by python-inspector causes a crash on pdt file parsing. Reference: #10734 Signed-off-by: Helio Chissini de Castro <[email protected]>
1 parent 0322aba commit 78fb251

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

plugins/package-managers/python/src/main/kotlin/utils/PythonInspector.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal object PythonInspector : CommandLineTool {
111111
val packagePurls = mutableSetOf<String>()
112112
binaryResult.projects.forEach { project ->
113113
project.packageData.forEach { data ->
114-
data.dependencies.mapTo(packagePurls) { it.purl }
114+
data.dependencies.mapNotNullTo(packagePurls) { it.purl }
115115
}
116116
}
117117

@@ -121,7 +121,7 @@ internal object PythonInspector : CommandLineTool {
121121
"(${binaryResult.packages.size}), which might indicate a bug in python-inspector."
122122
}
123123

124-
val resultsPurls = binaryResult.packages.mapTo(mutableSetOf()) { it.purl }
124+
val resultsPurls = binaryResult.packages.mapNotNullTo(mutableSetOf()) { it.purl }
125125
logger.warn { "Packages that are not contained as dependencies: ${packagePurls - resultsPurls}" }
126126
logger.warn { "Dependencies that are not contained as packages: ${resultsPurls - packagePurls}" }
127127
}
@@ -174,7 +174,7 @@ internal object PythonInspector : CommandLineTool {
174174

175175
@Serializable
176176
internal data class Dependency(
177-
val purl: String,
177+
val purl: String?,
178178
val scope: String,
179179
val isRuntime: Boolean,
180180
val isOptional: Boolean,
@@ -213,7 +213,7 @@ internal object PythonInspector : CommandLineTool {
213213
val repositoryHomepageUrl: String?,
214214
val repositoryDownloadUrl: String?,
215215
val apiDataUrl: String,
216-
val purl: String
216+
val purl: String?
217217
)
218218

219219
@Serializable

plugins/package-managers/python/src/main/kotlin/utils/PythonInspectorExtensions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.ossreviewtoolkit.model.RemoteArtifact
3232
import org.ossreviewtoolkit.model.Scope
3333
import org.ossreviewtoolkit.model.VcsInfo
3434
import org.ossreviewtoolkit.model.VcsType
35+
import org.ossreviewtoolkit.model.utils.toPurl
3536

3637
private const val TYPE = "PyPI"
3738

@@ -142,7 +143,7 @@ internal fun List<PythonInspector.Package>.toOrtPackages(): Set<Package> =
142143
// The package has a namespace property which is currently always empty. Deliberately set the namespace to
143144
// an empty string here to be consistent with the resolved packages which do not have a namespace property.
144145
id = id,
145-
purl = pkg.purl,
146+
purl = pkg.purl ?: id.toPurl(),
146147
authors = pkg.parties.toAuthors(),
147148
declaredLicenses = declaredLicenses,
148149
declaredLicensesProcessed = declaredLicensesProcessed,

0 commit comments

Comments
 (0)