Skip to content

Commit 5491c82

Browse files
authored
Fix constant Gitpod Plugin exception on Gateway startup (#20291)
1 parent 41b6404 commit 5491c82

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/auth/GitpodAuthCallbackHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import org.jetbrains.io.response
1616
import java.nio.charset.StandardCharsets
1717

1818
internal class GitpodAuthCallbackHandler : RestService() {
19-
private val service = GitpodAuthService.instance
19+
private val service = GitpodAuthService.instance.get()
2020

2121
override fun getServiceName(): String = service.name
2222

components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/auth/GitpodAuthService.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import com.intellij.credentialStore.CredentialAttributes
1717
import com.intellij.credentialStore.generateServiceName
1818
import com.intellij.ide.passwordSafe.PasswordSafe
1919
import com.intellij.openapi.Disposable
20+
import com.intellij.openapi.application.CachedSingletonsRegistry
2021
import com.intellij.openapi.components.Service
2122
import com.intellij.openapi.components.service
23+
import com.intellij.openapi.diagnostic.thisLogger
2224
import com.intellij.util.EventDispatcher
2325
import com.intellij.util.Url
2426
import com.intellij.util.Urls.encodeParameters
@@ -35,6 +37,7 @@ import java.net.http.HttpResponse
3537
import java.security.SecureRandom
3638
import java.util.*
3739
import java.util.concurrent.CompletableFuture
40+
import java.util.function.Supplier
3841
import kotlin.math.absoluteValue
3942

4043
@Service
@@ -148,7 +151,8 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
148151
}
149152

150153
companion object {
151-
val instance: GitpodAuthService = service()
154+
@Suppress("UnstableApiUsage")
155+
val instance: Supplier<GitpodAuthService> = CachedSingletonsRegistry.lazy { service() }
152156

153157
private const val SERVICE_NAME = "gitpod/oauth"
154158
private const val CLIENT_ID = "jetbrains-gateway-gitpod-plugin"
@@ -176,7 +180,7 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
176180
}
177181

178182
suspend fun authorize(gitpodHost: String): String {
179-
val accessToken = instance.authorize(gitpodHost).await().accessToken
183+
val accessToken = instance.get().authorize(gitpodHost).await().accessToken
180184
setAccessToken(gitpodHost, accessToken)
181185
return accessToken
182186
}

0 commit comments

Comments
 (0)