fix: SettingsKey circular init crash on app start

SENSITIVE_KEYS and SENSITIVE_KEY_STRINGS used eager initialization in the
companion object. When E2EEKeyManager.hasKeyPair() was the first access to
SettingsKey, it triggered SettingsKey.<clinit> which tried to resolve
StringKey.E2EEPrivateKeyset - but that class was already 'in initialization
by the current thread' (JVM spec). The JVM returned null, causing NPE in
SENSITIVE_KEY_STRINGS.map { it.key }.

Fix: use by lazy for both properties to defer initialization past <clinit>.
This commit is contained in:
Jens Reinemann 2026-05-18 00:39:32 +02:00
parent d02a38455b
commit ea02029dbe

View file

@ -27,16 +27,18 @@ internal sealed class SettingsKey<T>(val key: String, val defaultValue: T) {
companion object { companion object {
const val DEFAULT_SERVER_URL = "https://bollwerk.online" const val DEFAULT_SERVER_URL = "https://bollwerk.online"
val SENSITIVE_KEYS: Set<StringKey> = setOf( val SENSITIVE_KEYS: Set<StringKey> by lazy {
StringKey.AuthAccessToken, setOf(
StringKey.AuthRefreshToken, StringKey.AuthAccessToken,
StringKey.AuthUsername, StringKey.AuthRefreshToken,
StringKey.AuthUserId, StringKey.AuthUsername,
StringKey.OpenAiApiKey, StringKey.AuthUserId,
StringKey.E2EEPrivateKeyset, StringKey.OpenAiApiKey,
StringKey.E2EEPublicKeyBase64 StringKey.E2EEPrivateKeyset,
) StringKey.E2EEPublicKeyBase64
)
}
val SENSITIVE_KEY_STRINGS: Set<String> = SENSITIVE_KEYS.map { it.key }.toSet() val SENSITIVE_KEY_STRINGS: Set<String> by lazy { SENSITIVE_KEYS.map { it.key }.toSet() }
} }
} }