From 66e4a01e6fdbd53ea5ff47e25ef7e2bc2e36c24e Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 6 Aug 2026 10:05:52 +0200 Subject: [PATCH] fix: don't load session_util from ProStatusManager class init The companion `val`s reading SessionProtocol.PRO_HIGHER_CHARACTER_LIMIT / STANDARD_CHARACTER_LIMIT were compiled into ProStatusManager.. SessionProtocol is an object extending LibSessionUtilCApi, whose constructor calls System.loadLibrary("session_util"), so merely class-loading ProStatusManager pulled in the native library. There is no session_util on the JVM, which broke `testPlayDebugUnitTest` on dev: mock() in ConversationViewModelTest.createViewModel failed with UnsatisfiedLinkError: no session_util in java.library.path and the 8 following tests died with NoClassDefFoundError (9 failures total). Read both limits through getters instead, keeping class init free of native side effects. SessionProtocol already caches them via `by lazy`, so each call site is still a field read, and the values are only fetched when a real ProStatusManager needs them. --- .../thoughtcrime/securesms/pro/ProStatusManager.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/pro/ProStatusManager.kt b/app/src/main/java/org/thoughtcrime/securesms/pro/ProStatusManager.kt index 455397ca39..7bf808822b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/pro/ProStatusManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/pro/ProStatusManager.kt @@ -491,9 +491,15 @@ class ProStatusManager @Inject constructor( } companion object { - // Single-sourced from libsession (see SessionProtocol) rather than hard-coded here. - val MAX_CHARACTER_PRO = SessionProtocol.PRO_HIGHER_CHARACTER_LIMIT // max message codepoints for pro users - private val MAX_CHARACTER_REGULAR = SessionProtocol.STANDARD_CHARACTER_LIMIT // max message codepoints for non-pro users + // Single-sourced from libsession (see SessionProtocol) rather than hard-coded here. Read + // through getters, not stored in the initialiser: touching SessionProtocol loads the + // session_util native library, and doing that from ProStatusManager's makes the + // class impossible to even load (let alone mock) on the JVM, where there is no native + // library. SessionProtocol already caches both values, so this stays a cheap field read. + val MAX_CHARACTER_PRO: Int // max message codepoints for pro users + get() = SessionProtocol.PRO_HIGHER_CHARACTER_LIMIT + private val MAX_CHARACTER_REGULAR: Int // max message codepoints for non-pro users + get() = SessionProtocol.STANDARD_CHARACTER_LIMIT const val MAX_PIN_REGULAR = 5 // max pinned conversation for non pro users const val URL_PRO_SUPPORT = "https://getsession.org/pro-form"