Skip to content

Commit 5de589f

Browse files
committed
fix: replace unsafe call of non-nullable symbol
With a takIf/let pattern. Theoretically you can have two threads racing - one changing the value of lastDeploymentURL and another \one reading. In our code that should be pretty much impossible. But the compiler can't be sure of that so it throws and error.
1 parent b6c6e7c commit 5de589f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/main/kotlin/com/coder/toolbox/CoderToolboxContext.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ data class CoderToolboxContext(
4242
*/
4343
val deploymentUrl: URL
4444
get() {
45-
if (!this.settingsStore.lastDeploymentURL.isNullOrBlank()) {
46-
return this.settingsStore.lastDeploymentURL!!.toURL()
47-
} else if (this.secrets.lastDeploymentURL.isNotBlank()) {
48-
return this.secrets.lastDeploymentURL.toURL()
49-
}
50-
return this.settingsStore.defaultURL.toURL()
45+
return settingsStore.lastDeploymentURL?.takeIf { it.isNotBlank() }?.toURL()
46+
?: secrets.lastDeploymentURL.takeIf { it.isNotBlank() }?.toURL()
47+
?: settingsStore.defaultURL.toURL()
5148
}
5249

5350
suspend fun logAndShowError(title: String, error: String) {

0 commit comments

Comments
 (0)