Skip to content

Commit 58a16d5

Browse files
fviernausschuberth
authored andcommitted
fix(spdx): Fix an issue with traversing nodes with the graph navigator
The node reference get invalidate after the scope passed to `visitDependencies()` is left. This results in the tree not being properly traversed, the map returned by `getLinkageTypesForDependencyRelationships()` lacks some keys, which in turn breaks the assumption made by a `getValue()` on that map [^1], which leads to a crash. Fix the traversal by simply executing the mapping to stable references within the scope of validity of the node references. [^1]: https://github.com/oss-review-toolkit/ort/blob/75891a2d28ea59be4808f5b41dadeaa60ebd288d/plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt#L74 Signed-off-by: Frank Viernau <frank.viernau@gmail.com>
1 parent 75891a2 commit 58a16d5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ private fun OrtResult.getLinkageTypesForDependencyRelationships():
235235
while (queue.isNotEmpty()) {
236236
val parent = queue.removeFirst()
237237

238-
val children = parent.visitDependencies { children -> children.map { it.getStableReference() } }
238+
val children = parent.visitDependencies { children ->
239+
// Map to a list instead of to a sequence, so that the conversion to the stable reference is done
240+
// within this code block. After leaving the block, the node reference are not valid anymore.
241+
children.mapTo(mutableListOf()) { it.getStableReference() }
242+
}
239243

240244
children.forEach { child ->
241245
result.getOrPut(parent.id to child.id) { mutableSetOf() } += child.linkage

0 commit comments

Comments
 (0)