Skip to content

Commit 4ee1030

Browse files
committedFeb 19, 2025
chore(spdx-utils): Add checkNotNull() calls to resource lookups
These are never supposed to fail. This gets rid of an inspection hint. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent 5d1803b commit 4ee1030

5 files changed

+8
-8
lines changed
 

‎utils/spdx/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fun Task.generateEnumClass(
271271
| * The map which associates SPDX exceptions with their applicable SPDX licenses.
272272
| */
273273
| val mapping by lazy {
274-
| val resource = SpdxLicenseException::class.java.getResource("/exception-mapping.yml")
274+
| val resource = checkNotNull(SpdxLicenseException::class.java.getResource("/exception-mapping.yml"))
275275
| yamlMapper.readValue<Map<String, List<SpdxLicense>>>(resource)
276276
| }
277277
|
@@ -300,7 +300,7 @@ fun Task.generateEnumClass(
300300
| /**
301301
| * The full $description text as a string.
302302
| */
303-
| val text by lazy { javaClass.getResource("/$resourcePath/${'$'}id").readText() }
303+
| val text by lazy { checkNotNull(javaClass.getResource("/$resourcePath/${'$'}id")).readText() }
304304
|}
305305
|
306306
""".trimMargin()

‎utils/spdx/src/main/kotlin/SpdxDeclaredLicenseMapping.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object SpdxDeclaredLicenseMapping {
3131
* The raw map which associates collected license strings with their corresponding SPDX expression.
3232
*/
3333
internal val rawMapping by lazy {
34-
val resource = javaClass.getResource("/declared-license-mapping.yml")
34+
val resource = checkNotNull(javaClass.getResource("/declared-license-mapping.yml"))
3535
yamlMapper.readValue<Map<String, SpdxExpression>>(resource)
3636
}
3737

‎utils/spdx/src/main/kotlin/SpdxLicense.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,5 +743,5 @@ enum class SpdxLicense(
743743
/**
744744
* The full license text as a string.
745745
*/
746-
val text by lazy { javaClass.getResource("/licenses/$id").readText() }
746+
val text by lazy { checkNotNull(javaClass.getResource("/licenses/$id")).readText() }
747747
}

‎utils/spdx/src/main/kotlin/SpdxLicenseException.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ enum class SpdxLicenseException(
128128
* The map which associates SPDX exceptions with their applicable SPDX licenses.
129129
*/
130130
val mapping by lazy {
131-
val resource = SpdxLicenseException::class.java.getResource("/exception-mapping.yml")
131+
val resource = checkNotNull(SpdxLicenseException::class.java.getResource("/exception-mapping.yml"))
132132
yamlMapper.readValue<Map<String, List<SpdxLicense>>>(resource)
133133
}
134134

@@ -144,5 +144,5 @@ enum class SpdxLicenseException(
144144
/**
145145
* The full license exception text as a string.
146146
*/
147-
val text by lazy { javaClass.getResource("/exceptions/$id").readText() }
147+
val text by lazy { checkNotNull(javaClass.getResource("/exceptions/$id")).readText() }
148148
}

‎utils/spdx/src/main/kotlin/SpdxSimpleLicenseMapping.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object SpdxSimpleLicenseMapping {
3131
* The raw map which associates custom license IDs with their corresponding SPDX license ID.
3232
*/
3333
internal val customLicenseIdsMap by lazy {
34-
val resource = javaClass.getResource("/simple-license-mapping.yml")
34+
val resource = checkNotNull(javaClass.getResource("/simple-license-mapping.yml"))
3535
yamlMapper.readValue<Map<String, SpdxLicense>>(resource)
3636
}
3737

@@ -45,7 +45,7 @@ object SpdxSimpleLicenseMapping {
4545
* The map of deprecated SPDX license ids associated with their current SPDX expression.
4646
*/
4747
private val deprecatedLicenseIds by lazy {
48-
val resource = javaClass.getResource("/deprecated-license-mapping.yml")
48+
val resource = checkNotNull(javaClass.getResource("/deprecated-license-mapping.yml"))
4949
yamlMapper.readValue<Map<String, SpdxSingleLicenseExpression>>(resource)
5050
}
5151

0 commit comments

Comments
 (0)
Please sign in to comment.