Skip to content

Commit 0060d4f

Browse files
committed
refactor: drop null handling the compiler now proves redundant
Kotlin 2.2 propagates nullability further, so a number of safe calls, !! assertions, elvis fallbacks and casts are now provably dead. Two of these hid real problems: MimeMessageParser pinned JavaMail platform types to non-null, which silently disabled its null checks even though getRecipients and getFrom do return null, and ValidationError cast a vararg Array<out String> to Array<String>.
1 parent 91e2be9 commit 0060d4f

37 files changed

Lines changed: 63 additions & 74 deletions

File tree

backend/api/src/main/kotlin/io/tolgee/hateoas/invitation/OrganizationInvitationModelAssembler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class OrganizationInvitationModelAssembler(
1818
return OrganizationInvitationModel(
1919
entity.id!!,
2020
entity.code,
21-
entity.organizationRole!!.type!!,
21+
entity.organizationRole!!.type,
2222
entity.createdAt!!,
2323
invitedUserName = entity.name,
2424
invitedUserEmail = entity.email,

backend/api/src/main/kotlin/io/tolgee/hateoas/organization/SimpleOrganizationModelAssembler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SimpleOrganizationModelAssembler(
1717
SimpleOrganizationModel::class.java,
1818
) {
1919
override fun toModel(entity: Organization): SimpleOrganizationModel {
20-
val link = linkTo<OrganizationController> { get(entity.slug ?: "") }.withSelfRel()
20+
val link = linkTo<OrganizationController> { get(entity.slug) }.withSelfRel()
2121
return SimpleOrganizationModel(
2222
entity.id,
2323
entity.name,

backend/api/src/main/kotlin/io/tolgee/hateoas/translations/suggestions/TranslationSuggestionModelAssembler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TranslationSuggestionModelAssembler(
1818
return TranslationSuggestionModel(
1919
id = entity.id,
2020
languageId = entity.language!!.id,
21-
keyId = entity.key!!.id,
21+
keyId = entity.key.id,
2222
translation = entity.translation,
2323
author = simpleUserAccountModelAssembler.toModel(entity.author!!),
2424
state = entity.state,

backend/app/src/main/kotlin/io/tolgee/ExceptionHandlers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ExceptionHandlers : Logging {
6969
@ExceptionHandler(MethodArgumentTypeMismatchException::class)
7070
fun handleValidationExceptions(ex: MethodArgumentTypeMismatchException): ResponseEntity<ErrorResponseBody> {
7171
return ResponseEntity(
72-
ErrorResponseBody(Message.WRONG_PARAM_TYPE.code, listOf(ex.parameter.parameterName) as List<Serializable>?),
72+
ErrorResponseBody(Message.WRONG_PARAM_TYPE.code, listOfNotNull(ex.parameter.parameterName)),
7373
HttpStatus.BAD_REQUEST,
7474
)
7575
}

backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translations/v2TranslationsController/TranslationsControllerHistoryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class TranslationsControllerHistoryTest : ProjectAuthControllerTest("/v2/project
119119
translationService.find(emptyKey, lang).get()
120120
}
121121

122-
performProjectAuthGet("/translations/${translation!!.id}/history").andPrettyPrint.andAssertThatJson {
122+
performProjectAuthGet("/translations/${translation.id}/history").andPrettyPrint.andAssertThatJson {
123123
node("page.totalElements").isEqualTo(0)
124124
}
125125
}

backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/V2ImportControllerAddFilesTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"
232232
assertThat(
233233
it.files[0]
234234
.issues[0]
235-
.params
236-
?.get(0)
237-
?.value,
235+
.params[0]
236+
.value,
238237
).isEqualTo("too_long")
239238
}
240239
}

backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ProjectsController/ProjectsControllerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ProjectsControllerTest : ProjectAuthControllerTest("/v2/projects/") {
219219
val usersAndOrganizations = dbPopulator.createUsersAndOrganizations()
220220
val repo = usersAndOrganizations[1].organizationRoles[0].organization!!.projects[0]
221221
val user = dbPopulator.createUserIfNotExists("jirina")
222-
organizationRoleService.grantOwnerRoleToUser(user, repo.organizationOwner!!)
222+
organizationRoleService.grantOwnerRoleToUser(user, repo.organizationOwner)
223223

224224
loginAsUser(usersAndOrganizations[1].name)
225225

backend/app/src/test/kotlin/io/tolgee/batch/AbstractBatchJobsGeneralTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ abstract class AbstractBatchJobsGeneralTest :
402402

403403
executions
404404
.last()
405-
.successTargets!!
405+
.successTargets
406406
.assert
407407
.size()
408408
.isEqualTo(2) // 2 failed items in a chunk are retried successfully

backend/app/src/test/kotlin/io/tolgee/controllers/ExportControllerTest.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import java.time.ZonedDateTime
2929
import java.time.format.DateTimeFormatter
3030
import java.util.Date
3131
import java.util.function.Consumer
32-
import java.util.zip.ZipEntry
3332
import java.util.zip.ZipInputStream
3433

3534
@AutoConfigureMockMvc
@@ -191,12 +190,9 @@ class ExportControllerTest : ProjectAuthControllerTest() {
191190
val byteArrayInputStream = ByteArrayInputStream(responseContent)
192191
val zipInputStream = ZipInputStream(byteArrayInputStream)
193192
val result = HashMap<String, Long>()
194-
var nextEntry: ZipEntry?
195-
while (zipInputStream.nextEntry.also {
196-
nextEntry = it
197-
} != null
198-
) {
199-
result[nextEntry!!.name] = nextEntry!!.size
193+
while (true) {
194+
val nextEntry = zipInputStream.nextEntry ?: break
195+
result[nextEntry.name] = nextEntry.size
200196
}
201197
return result
202198
}

backend/app/src/test/kotlin/io/tolgee/repository/ProjectRepositoryTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ProjectRepositoryTest {
6060
filters = ProjectFilters(),
6161
)
6262
assertThat(result).hasSize(10)
63-
assertThat(result.content[0].organizationOwner?.name).isNotNull
64-
assertThat(result.content[8].organizationOwner?.slug).isNotNull
63+
assertThat(result.content[0].organizationOwner.name).isNotNull
64+
assertThat(result.content[8].organizationOwner.slug).isNotNull
6565
}
6666
}

0 commit comments

Comments
 (0)