From d9dee8967b1b453acd8d2c20148c9ab5eb71f787 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Jul 2026 18:31:10 +0000 Subject: [PATCH] fix: resolve compiler warnings across modules Clears real Kotlin compiler warnings surfaced across quartz, cli, relayBench, amethyst, and desktopApp: - quartz Sha256/EventHasher/ScratchLocal: ThreadLocal.get() is nullable in Kotlin; assert non-null (withInitial never yields null). - quartz GitHttpClient: PriorityQueue.poll() under isNotEmpty() is non-null; assert it. - relayBench CorpusDownloader: drop redundant !! on smart-cast Long; Jackson fields() -> properties(). - cli GrapeRankCommand: drop redundant ?. where latest is smart-cast. - PodcastRemoteContent: OkHttp body is non-null; drop dead elvis. - Dead/redundant expressions: remove no-op when-branch values and a redundant trailing Unit (HomeScreen, LocalCache, EmbeddedTabLayer, ParticipantHostActionsSheet, NestActionBar, ControlWhenPlayerIsActive, ShareNoteAsImageScreen exhaustive-when else). - CalendarEventDetailScreen / SetPasswordDialog / ProfileClinkOfferResolver: drop always-true conditions (reorder to keep smart-casts). - WalletColumnScreen: OkHttp body non-null; drop unreachable null-guards. - PcmTapRegistry: the @OptIn used androidx.annotation.OptIn, which does not opt into Kotlin's ExperimentalCoroutinesApi; use kotlin.OptIn. - GitRepositoryScreen: suppress the standard ViewModel-factory cast. - PushNotificationReceiverService: suppress override-of-deprecated. - Desktop GlobalScope call sites: @OptIn(DelicateCoroutinesApi::class). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_016GMqkg1ndvFihEwZcENiRs --- .../com/vitorpamplona/amethyst/model/LocalCache.kt | 1 - .../playback/composable/ControlWhenPlayerIsActive.kt | 4 +--- .../service/playback/playerPool/PcmTapRegistry.kt | 2 +- .../service/podcasts/PodcastRemoteContent.kt | 2 +- .../amethyst/ui/note/share/ShareNoteAsImageScreen.kt | 2 -- .../calendars/detail/CalendarEventDetailScreen.kt | 2 +- .../ui/screen/loggedIn/embed/EmbeddedTabLayer.kt | 1 - .../screen/loggedIn/gitRepo/GitRepositoryScreen.kt | 1 + .../amethyst/ui/screen/loggedIn/home/HomeScreen.kt | 6 +++--- .../room/participants/ParticipantHostActionsSheet.kt | 4 +--- .../loggedIn/nests/room/screen/NestActionBar.kt | 4 +--- .../profile/payment/ProfileClinkOfferResolver.kt | 2 +- .../notifications/PushNotificationReceiverService.kt | 1 + .../amethyst/cli/commands/GrapeRankCommand.kt | 4 ++-- .../amethyst/desktop/cache/DesktopLocalCache.kt | 2 ++ .../amethyst/desktop/security/SetPasswordDialog.kt | 2 +- .../vitorpamplona/amethyst/desktop/ui/NoteActions.kt | 3 +++ .../amethyst/desktop/ui/deck/LocalFeedProvider.kt | 3 +++ .../amethyst/desktop/ui/wallet/WalletColumnScreen.kt | 12 ++---------- .../quartz/utils/secp256k1/ScratchLocal.android.kt | 5 ++--- .../crypto/EventHasherSerializer.jvmAndroid.kt | 2 +- .../quartz/nip34Git/git/GitHttpClient.kt | 2 +- .../quartz/utils/sha256/Sha256.jvmAndroid.kt | 8 ++++---- .../relaybench/corpus/CorpusDownloader.kt | 6 +++--- 24 files changed, 36 insertions(+), 45 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index b5c27ae39f..cfadfd38fb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -2525,7 +2525,6 @@ object LocalCache : ILocalCache, ICacheProvider { } } catch (e: Exception) { if (e is CancellationException) throw e - null } return liveChatChannels.filter { _, channel -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/ControlWhenPlayerIsActive.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/ControlWhenPlayerIsActive.kt index f955953c93..ff69a65ff0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/ControlWhenPlayerIsActive.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/ControlWhenPlayerIsActive.kt @@ -108,9 +108,7 @@ fun ControlWhenPlayerIsActive( } } - else -> { - Unit - } + else -> {} } } lifecycleOwner.lifecycle.addObserver(observer) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/PcmTapRegistry.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/PcmTapRegistry.kt index 8416f986db..62129db719 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/PcmTapRegistry.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/PcmTapRegistry.kt @@ -65,7 +65,7 @@ class SpectrumAudioBufferSink( private var channels = 1 private var encoding = C.ENCODING_PCM_16BIT - @OptIn(ExperimentalCoroutinesApi::class) + @kotlin.OptIn(ExperimentalCoroutinesApi::class) override fun flush( sampleRateHz: Int, channelCount: Int, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/podcasts/PodcastRemoteContent.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/podcasts/PodcastRemoteContent.kt index 5fafb991be..57fcf4ec33 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/podcasts/PodcastRemoteContent.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/podcasts/PodcastRemoteContent.kt @@ -50,7 +50,7 @@ object PodcastRemoteContent { .build() okHttpClient.newCall(request).executeAsync().use { response -> if (!response.isSuccessful) return@use null - val body = response.body ?: return@use null + val body = response.body // Reject an oversized declared length outright; cap the read for chunked bodies. if (body.contentLength() > MAX_BYTES) return@use null body.string().take(MAX_BYTES.toInt()) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/share/ShareNoteAsImageScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/share/ShareNoteAsImageScreen.kt index 9b6fc4a151..f82ca37bcd 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/share/ShareNoteAsImageScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/share/ShareNoteAsImageScreen.kt @@ -285,8 +285,6 @@ fun ShareNoteAsImageScreen( *finalState.params, ) } - - else -> {} } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/calendars/detail/CalendarEventDetailScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/calendars/detail/CalendarEventDetailScreen.kt index 7d68d70882..e25c76a2be 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/calendars/detail/CalendarEventDetailScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/calendars/detail/CalendarEventDetailScreen.kt @@ -215,7 +215,7 @@ fun CalendarEventDetailScreen( } // The Edit affordance is only meaningful when the current account is the // author — relays will reject a signed-by-stranger replacement. - if (isOwnEvent && event != null) { + if (isOwnEvent) { IconButton(onClick = { nav.nav( Route.EditCalendarEvent( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/embed/EmbeddedTabLayer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/embed/EmbeddedTabLayer.kt index 98584c6460..fcf118d781 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/embed/EmbeddedTabLayer.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/embed/EmbeddedTabLayer.kt @@ -559,7 +559,6 @@ fun EmbeddedTabLayer(barFavoriteIds: List) { "Copy" to { val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipboard.setPrimaryClip(ClipData.newPlainText("selection", pageSel.text)) - Unit }, ), onMagnify = onMagnify, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/gitRepo/GitRepositoryScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/gitRepo/GitRepositoryScreen.kt index 6298397653..56157e82f3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/gitRepo/GitRepositoryScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/gitRepo/GitRepositoryScreen.kt @@ -163,6 +163,7 @@ fun GitRepositoryPullsScreen( internal class GitRepositoryBrowserViewModelFactory( private val okHttpClient: (String) -> OkHttpClient, ) : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T = GitRepositoryBrowserViewModel(okHttpClient) as T } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/HomeScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/HomeScreen.kt index 514335a40d..fc2f1a88ab 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/HomeScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/HomeScreen.kt @@ -460,10 +460,10 @@ fun DisplayLiveBubbles( val feedState by liveSection.feedContent.collectAsStateWithLifecycle() when (val state = feedState) { - is ChannelFeedState.Empty -> null - is ChannelFeedState.FeedError -> null + is ChannelFeedState.Empty -> {} + is ChannelFeedState.FeedError -> {} is ChannelFeedState.Loaded -> DisplayLiveBubbles(state, accountViewModel, nav) - is ChannelFeedState.Loading -> null + is ChannelFeedState.Loading -> {} } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/participants/ParticipantHostActionsSheet.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/participants/ParticipantHostActionsSheet.kt index deaceab27d..d466830ba1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/participants/ParticipantHostActionsSheet.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/participants/ParticipantHostActionsSheet.kt @@ -199,9 +199,7 @@ internal fun ParticipantHostActionsSheet( ) } - null -> { - Unit - } + null -> {} } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/screen/NestActionBar.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/screen/NestActionBar.kt index 274b9b3cae..951ec72a3f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/screen/NestActionBar.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/screen/NestActionBar.kt @@ -255,9 +255,7 @@ private fun StartCluster( // On-stage controls live in [StageControlsBar]; audience // has nothing to do here (system volume keys are enough). - is ConnectionUiState.Connected -> { - Unit - } + is ConnectionUiState.Connected -> {} } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/payment/ProfileClinkOfferResolver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/payment/ProfileClinkOfferResolver.kt index 4228e0348d..a7f62be4e2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/payment/ProfileClinkOfferResolver.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/payment/ProfileClinkOfferResolver.kt @@ -76,7 +76,7 @@ fun rememberProfileClinkOffer( // Fall back to the NIP-05 .well-known clink_offer (cached per address). val id = nip05?.let { Nip05Id.parse(it) } offer = - if (id != null && nip05 != null) { + if (nip05 != null && id != null) { // Distinguish "cache miss" from a cached "no offer" (null) so we don't refetch. val cacheKey = nip05.lowercase() val cached = clinkOfferNip05Cache.get(cacheKey) diff --git a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt index 599860025f..064d951d04 100644 --- a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt +++ b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt @@ -86,6 +86,7 @@ class PushNotificationReceiverService : FirebaseMessagingService() { super.onDestroy() } + @Suppress("OVERRIDE_DEPRECATION") override fun onNewToken(token: String) { scope.launch(Dispatchers.IO) { Log.d("PushNotificationService", "PushNotificationReceiverService.onNewToken") diff --git a/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/GrapeRankCommand.kt b/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/GrapeRankCommand.kt index 0057498da6..d01bed2eef 100644 --- a/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/GrapeRankCommand.kt +++ b/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/GrapeRankCommand.kt @@ -568,7 +568,7 @@ object GrapeRankCommand { "provider" to provider, "relay" to relay.url, "changed" to false, - "based_on" to latest?.id, + "based_on" to latest.id, ), ) return 0 @@ -744,7 +744,7 @@ object GrapeRankCommand { latest?.serviceProviders()?.any { it.service == service && it.pubkey == providerPubkey && it.relayUrl == relay } ?: false - if (alreadyListed) return latest?.id + if (alreadyListed) return latest.id val tag = ServiceProviderTag(service, providerPubkey, relay) val event = diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/cache/DesktopLocalCache.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/cache/DesktopLocalCache.kt index 2212833b67..fc762421e9 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/cache/DesktopLocalCache.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/cache/DesktopLocalCache.kt @@ -60,6 +60,7 @@ import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent import com.vitorpamplona.quartz.utils.DualCase import com.vitorpamplona.quartz.utils.Log import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.BufferOverflow @@ -711,6 +712,7 @@ class DesktopLocalCache : ICacheProvider { * @param relay The relay this event came from * @return true if event was processed, false if no matching request */ + @OptIn(DelicateCoroutinesApi::class) fun consume( event: LnZapPaymentResponseEvent, relay: NormalizedRelayUrl?, diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/security/SetPasswordDialog.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/security/SetPasswordDialog.kt index de88a4d3df..8b9d08f0a2 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/security/SetPasswordDialog.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/security/SetPasswordDialog.kt @@ -104,7 +104,7 @@ fun SetPasswordDialog( val submit: () -> Unit = { val currentOk = !isChange || - (existingHash != null && PasswordHasher.verify(current.toCharArray(), existingHash)) + PasswordHasher.verify(current.toCharArray(), existingHash) when { !currentOk -> { currentError = "Wrong password" diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/NoteActions.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/NoteActions.kt index 83806d8395..7a52fb1d08 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/NoteActions.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/NoteActions.kt @@ -103,6 +103,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip47WalletConnect.Nip47WalletConnect import com.vitorpamplona.quartz.nip51Lists.bookmarkList.BookmarkListEvent import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine @@ -818,6 +819,7 @@ fun BoostsPopup( /** * Fetches metadata for multiple users in a single subscription. */ +@OptIn(DelicateCoroutinesApi::class) private suspend fun fetchMetadataForUsers( pubKeys: List, relayManager: DesktopRelayConnectionManager, @@ -1584,6 +1586,7 @@ private fun openLightningUri(bolt11: String) { * Fetches user metadata on-demand to get lightning address. * Returns the lightning address if found, null otherwise. */ +@OptIn(DelicateCoroutinesApi::class) private suspend fun fetchUserLightningAddress( pubKey: String, relayManager: DesktopRelayConnectionManager, diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/deck/LocalFeedProvider.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/deck/LocalFeedProvider.kt index 299e5afa5b..5648051598 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/deck/LocalFeedProvider.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/deck/LocalFeedProvider.kt @@ -27,6 +27,7 @@ import com.vitorpamplona.amethyst.commons.feeds.custom.defaultFeeds import com.vitorpamplona.amethyst.desktop.cache.DesktopLocalCache import com.vitorpamplona.amethyst.desktop.network.DesktopRelayConnectionManager import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -38,6 +39,7 @@ private val feedPrefs: Preferences by lazy { Preferences.userRoot().node("amethyst/feeds") } +@OptIn(DelicateCoroutinesApi::class) private val defaultRepository by lazy { val repo = FeedDefinitionRepository(GlobalScope) @@ -66,6 +68,7 @@ val LocalFeedRepository = defaultRepository } +@OptIn(DelicateCoroutinesApi::class) val LocalFeedScope = compositionLocalOf { GlobalScope diff --git a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/wallet/WalletColumnScreen.kt b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/wallet/WalletColumnScreen.kt index 21d0a15a1e..3027d35da4 100644 --- a/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/wallet/WalletColumnScreen.kt +++ b/desktopApp/src/jvmMain/kotlin/com/vitorpamplona/amethyst/desktop/ui/wallet/WalletColumnScreen.kt @@ -564,11 +564,7 @@ private fun SendDialog( kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { httpClient.newCall(request).execute() } - val body = response.body?.string() - if (body == null) { - sendState = SendState.Error("Failed to reach payment server", SendState.Idle) - return@LaunchedEffect - } + val body = response.body.string() val json = mapper.readTree(body) val callback = json.get("callback")?.asText()?.ifBlank { null } if (callback == null) { @@ -611,11 +607,7 @@ private fun SendDialog( kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { httpClient.newCall(request).execute() } - val body = response.body?.string() - if (body == null) { - sendState = SendState.Error("Failed to fetch invoice", SendState.Idle) - return@LaunchedEffect - } + val body = response.body.string() val json = mapper.readTree(body) val pr = json.get("pr")?.asText()?.ifBlank { null } if (pr != null) { diff --git a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/secp256k1/ScratchLocal.android.kt b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/secp256k1/ScratchLocal.android.kt index 503bc52b41..dd2927ce38 100644 --- a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/secp256k1/ScratchLocal.android.kt +++ b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/secp256k1/ScratchLocal.android.kt @@ -24,8 +24,7 @@ package com.vitorpamplona.quartz.utils.secp256k1 internal actual class ScratchLocal actual constructor( initializer: () -> T, ) { - private val tl = ThreadLocal.withInitial(initializer) + private val tl: ThreadLocal = ThreadLocal.withInitial(initializer) - @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") - actual fun get(): T = tl.get() + actual fun get(): T = tl.get()!! } diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/crypto/EventHasherSerializer.jvmAndroid.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/crypto/EventHasherSerializer.jvmAndroid.kt index fc98a34b8a..89f3f2dafe 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/crypto/EventHasherSerializer.jvmAndroid.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/crypto/EventHasherSerializer.jvmAndroid.kt @@ -127,7 +127,7 @@ actual object EventHasherSerializer { content: String, ): Boolean { val br: BufferRecycler = JacksonMapper.mapper.factory._getBufferRecycler() - val digest = threadLocalDigest.get() + val digest = threadLocalDigest.get()!! val bb = HashingByteArrayBuilder(br, digest) try { val generator = JacksonMapper.mapper.createGenerator(bb, JsonEncoding.UTF8) diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip34Git/git/GitHttpClient.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip34Git/git/GitHttpClient.kt index 8c296f5ea7..846bcf0374 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip34Git/git/GitHttpClient.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip34Git/git/GitHttpClient.kt @@ -162,7 +162,7 @@ class GitHttpClient( visited.add(start) } while (frontier.isNotEmpty() && result.size < depth) { - val commit = frontier.poll() + val commit = frontier.poll()!! result.add(commit) for (parent in commit.parents) { if (parent !in visited) { diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/utils/sha256/Sha256.jvmAndroid.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/utils/sha256/Sha256.jvmAndroid.kt index b58969cf6f..8453460097 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/utils/sha256/Sha256.jvmAndroid.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/utils/sha256/Sha256.jvmAndroid.kt @@ -30,19 +30,19 @@ import java.security.MessageDigest * (lock acquire + release) for ~2µs of actual hashing. ThreadLocal eliminates all locking * since each thread gets its own MessageDigest instance. digest() implicitly resets state. */ -val threadLocalDigest = +val threadLocalDigest: ThreadLocal = ThreadLocal.withInitial { MessageDigest.getInstance("SHA-256") } -actual fun sha256(data: ByteArray): ByteArray = threadLocalDigest.get().digest(data) +actual fun sha256(data: ByteArray): ByteArray = threadLocalDigest.get()!!.digest(data) actual fun sha256Into( out: ByteArray, data: ByteArray, len: Int, ): ByteArray { - val md = threadLocalDigest.get() + val md = threadLocalDigest.get()!! md.update(data, 0, len) md.digest(out, 0, 32) return out @@ -62,7 +62,7 @@ fun sha256StreamWithCount( bufferSize: Int = 8192, ): Pair { val countingStream = CountingInputStream(inputStream) - val digest = threadLocalDigest.get() + val digest = threadLocalDigest.get()!! try { val buffer = ByteArray(bufferSize) var bytesRead: Int diff --git a/relayBench/src/main/kotlin/com/vitorpamplona/relaybench/corpus/CorpusDownloader.kt b/relayBench/src/main/kotlin/com/vitorpamplona/relaybench/corpus/CorpusDownloader.kt index 530b09ec5b..d3c3b3965f 100644 --- a/relayBench/src/main/kotlin/com/vitorpamplona/relaybench/corpus/CorpusDownloader.kt +++ b/relayBench/src/main/kotlin/com/vitorpamplona/relaybench/corpus/CorpusDownloader.kt @@ -99,7 +99,7 @@ object CorpusDownloader { } } if (checkpoint.exists()) { - runCatching { mapper.readTree(checkpoint.readText()) }.getOrNull()?.fields()?.forEach { (url, until) -> + runCatching { mapper.readTree(checkpoint.readText()) }.getOrNull()?.properties()?.forEach { (url, until) -> cursors[url] = until.asLong() } } @@ -228,9 +228,9 @@ object CorpusDownloader { added += fresh val oldest = page.minOf { it.createdAt } until = - if (fresh == 0 && until != null && oldest >= until!!) { + if (fresh == 0 && until != null && oldest >= until) { // >PAGE_LIMIT events in this second and we have them all. - until!! - 1 + until - 1 } else { oldest }