Skip to content

Commit 73dd971

Browse files
nnobelissschuberth
authored andcommitted
fix(fossid-webapp): comments can be an empty array
FossId versions before 24.3.2 did not return the "comments" property when it was empty. Now it returns '[]' for this property value which is problematic, as it introduces polymorphism (a non-empty 'comments' property contains a map of integer to object). According to FossId support, "This is the default behaviour of the json_encode() function in PHP. An empty [] or empty {} should be handled in a similar way in integrations as they both represent the lack of elements". In all cases, ORT must support this behavior. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent 204a248 commit 73dd971

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

clients/fossid-webapp/src/main/kotlin/model/identification/markedAsIdentified/MarkedAsIdentifiedFile.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ package org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentif
2121

2222
import com.fasterxml.jackson.annotation.JsonUnwrapped
2323

24+
import org.ossreviewtoolkit.clients.fossid.PolymorphicData
2425
import org.ossreviewtoolkit.clients.fossid.model.identification.common.Component
2526
import org.ossreviewtoolkit.clients.fossid.model.summary.License
2627
import org.ossreviewtoolkit.clients.fossid.model.summary.Summarizable
2728
import org.ossreviewtoolkit.clients.fossid.model.summary.SummaryIdentifiedFile
2829

2930
data class MarkedAsIdentifiedFile(
3031
val comment: String?,
31-
val comments: Map<Int, Comment> = emptyMap(),
32+
val comments: PolymorphicData<Map<Int, Comment>> = PolymorphicData(emptyMap()),
3233

3334
val identificationId: Int,
3435

clients/fossid-webapp/src/test/resources/return-type/__files/body-list_scan_for_project_not_empty.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,36 @@
6666
"component_identified_date": "2025-12-08 09:13:10"
6767
}
6868
}
69+
},
70+
"4": {
71+
"row_id": "2",
72+
"file_id": "4611459",
73+
"file_path": "src/main/java/com/example/client/response/ReportRequest.java",
74+
"is_distributed": "1",
75+
"file_md5": "b8a8c00bf1dea4d52cb6a842b7affe08",
76+
"file_sha1": "da7c6657784025f38d5bb64733004ca01aa17ac0",
77+
"file_sha256": "af0254a01efd2ff2bdabce1299d8232625025330c711cf8bece7e566596aea2f",
78+
"file_size": "377",
79+
"identification_id": "29648306",
80+
"identification_copyright": null,
81+
"components": {
82+
"352": {
83+
"identification_id": 29648306,
84+
"component_id": 352,
85+
"component_name": "Original Code",
86+
"component_version": "Unspecified",
87+
"component_copyright": null,
88+
"component_cpe": null,
89+
"component_license_name": "[template] Basic Proprietary Commercial License",
90+
"component_license_identifier": "[template] Basic Proprietary Commercial License",
91+
"component_license_is_foss": 0,
92+
"component_license_is_spdx_standard": 0,
93+
"component_include_in_report": 1,
94+
"component_is_copyleft": 0,
95+
"component_identified_date": "2025-12-08 09:13:10"
96+
}
97+
},
98+
"comments": []
6999
}
70100
}
71101
}

plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal fun <T : Summarizable> List<T>.mapSummary(
147147
var fileComment: OrtComment? = null
148148

149149
if (summarizable is MarkedAsIdentifiedFile) {
150-
summarizable.comments.values.firstOrNull {
150+
summarizable.comments.value?.values?.firstOrNull {
151151
ORT_NAME in it.comment
152152
}?.also {
153153
runCatching {
@@ -453,7 +453,7 @@ internal fun listUnmatchedSnippetChoices(
453453
it.given.sourceLocation.path == markedFileNameWithoutPrefix
454454
}
455455

456-
val comment = markedAsIdentifiedFile.comments.values.firstOrNull {
456+
val comment = markedAsIdentifiedFile.comments.value?.values?.firstOrNull {
457457
ORT_NAME in it.comment
458458
}?.runCatching {
459459
jsonMapper.readValue(this.comment, OrtComment::class.java)

plugins/scanners/fossid/src/test/kotlin/TestUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ internal fun createMarkAsIdentifiedFile(
415415

416416
return MarkedAsIdentifiedFile(
417417
comment = "comment",
418-
comments = if (comment == null) emptyMap() else mapOf(1 to Comment(1, 1, comment)),
418+
comments = PolymorphicData(if (comment == null) emptyMap() else mapOf(1 to Comment(1, 1, comment))),
419419
identificationId = 1,
420420
identificationCopyright = "copyright",
421421
isDistributed = 1,

0 commit comments

Comments
 (0)