Skip to content

Commit 761729b

Browse files
nnobelissschuberth
authored andcommitted
fix(fossid-webapp): File.licenses can be an empty array
FossId versions before 24.3.2 did not return the "file_licenses" property when it was empty. Now it returns '[]' for this property value which is problematic, as it introduces polymorphism (a non-empty 'file_licenses' property contains a map of integer to object). Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent 73dd971 commit 761729b

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified
2121

22+
import org.ossreviewtoolkit.clients.fossid.PolymorphicData
23+
2224
data class File(
2325
val id: String?,
2426

@@ -29,5 +31,5 @@ data class File(
2931

3032
val size: Int?,
3133

32-
val licenses: MutableMap<Int, License>?
34+
val licenses: PolymorphicData<MutableMap<Int, License>>?
3335
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ data class MarkedAsIdentifiedFile(
4646
lateinit var file: File
4747

4848
override fun toSummary(): SummaryIdentifiedFile {
49-
val licenses = file.licenses?.let { licenses ->
49+
val licenses = file.licenses?.value?.let { licenses ->
5050
licenses.values.map {
5151
License(
5252
identifier = checkNotNull(it.file.licenseIdentifier),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"file_sha1": "da7c6657784025f38d5bb64733004ca01aa17ac0",
7777
"file_sha256": "af0254a01efd2ff2bdabce1299d8232625025330c711cf8bece7e566596aea2f",
7878
"file_size": "377",
79+
"file_licenses": [],
7980
"identification_id": "29648306",
8081
"identification_copyright": null,
8182
"components": {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private fun createMarkedIdentifiedFile(index: Int): MarkedAsIdentifiedFile {
379379
sha1 = null,
380380
sha256 = null,
381381
size = index,
382-
licenses = mutableMapOf(index to license)
382+
licenses = PolymorphicData(mutableMapOf(index to license))
383383
)
384384

385385
return file
@@ -428,7 +428,7 @@ internal fun createMarkAsIdentifiedFile(
428428
sha1 = "fileSha1",
429429
sha256 = "fileSha256",
430430
size = 0,
431-
licenses = if (comment != null) null else mutableMapOf(1 to fileLicense)
431+
licenses = PolymorphicData(if (comment != null) null else mutableMapOf(1 to fileLicense))
432432
)
433433
}
434434
}

0 commit comments

Comments
 (0)