From 404fc3e7b38bd9136996549da8905df5406d6c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= <228650+andresilveirah@users.noreply.github.com> Date: Fri, 13 Mar 2026 09:51:37 +0100 Subject: [PATCH 1/2] prevent messageUI from being created on finished() --- .../java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index 03cd2682b..dd2e0b2bb 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -435,7 +435,7 @@ class SpConsentLibMobileCore( } override fun finished(view: View) { - getOrCreateMessageUI().isPresenting = false + messageUI?.isPresenting = false runOnMain { spClient.onUIFinished(view) } renderNextMessageIfAny() } From f8ba84eea13b5d6c4c96dd0a6eb6a72b2dffec70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= <228650+andresilveirah@users.noreply.github.com> Date: Mon, 23 Mar 2026 17:56:43 +0100 Subject: [PATCH 2/2] remove messageUI before setting it to null --- .../cmplibrary/SpConsentLibMobileCore.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index dd2e0b2bb..bb7033bb7 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -86,7 +86,7 @@ class SpConsentLibMobileCore( } // used to store accessibility state of main view's children - private var a11ySnapshot: WeakHashMap = WeakHashMap() + private var a11ySnapshot: WeakHashMap = WeakHashMap() private var messageUI: SPMessageUI? = null fun getOrCreateMessageUI(): SPMessageUI { @@ -139,7 +139,7 @@ class SpConsentLibMobileCore( private fun renderNextMessageIfAny() = if (pendingActions == 0 && messagesToDisplay.isEmpty()) { - messageUI = null + disposeMessageUI() spClient.onSpFinished(spConsents) } else if (messagesToDisplay.isNotEmpty()) { val messageToRender = messagesToDisplay.removeFirst() @@ -311,11 +311,17 @@ class SpConsentLibMobileCore( private fun restoreChildrenA11y() { for ((view, accessibilityState) in a11ySnapshot.entries.toList()) { - view.importantForAccessibility = accessibilityState + view?.importantForAccessibility = accessibilityState } a11ySnapshot.clear() } + private fun disposeMessageUI() { + // Remove view from parent before nullifying to avoid NPE in ViewGroup + messageUI?.let { removeView(it as View) } + messageUI = null + } + override fun showView(view: View) { mainView?.let { parentView -> view.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) @@ -382,7 +388,7 @@ class SpConsentLibMobileCore( spClient.onConsentReady(SPConsents(userData)) pendingActions-- if (pendingActions == 0) { - messageUI = null + disposeMessageUI() spClient.onSpFinished(spConsents) } }.onFailure { @@ -396,7 +402,7 @@ class SpConsentLibMobileCore( finished(view) } ActionType.PM_DISMISS -> { - if (getOrCreateMessageUI().isFirstLayer) { + if (messageUI?.isFirstLayer == true) { pendingActions-- finished(view) }