Skip to content

[SDK-417] Fail gracefully when managers accessed before init#1073

Open
franco-zalamena-iterable wants to merge 1 commit into
masterfrom
feature/SDK-417-graceful-preinit
Open

[SDK-417] Fail gracefully when managers accessed before init#1073
franco-zalamena-iterable wants to merge 1 commit into
masterfrom
feature/SDK-417-graceful-preinit

Conversation

@franco-zalamena-iterable

@franco-zalamena-iterable franco-zalamena-iterable commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🔹 Jira Ticket(s) if any

✏️ Description

Fix to prevent calls before initialization to crash the app. We now log an error and have a new way to get the Iterable instance or null on the spot.

getInAppManager() and getEmbeddedManager() threw a RuntimeException when
called before IterableApi.initialize(), crashing the host app for a call-
ordering mistake. They now log a warning and return a no-op manager (empty
lists, ignored commands) instead, matching the iOS SDK's null-object model.

The getters keep their concrete @nonnull return types, so no existing call
site or test needs to change. Two no-op subclasses (EmptyInAppManager,
EmptyEmbeddedManager) back the stub. New getInAppManagerOrNull() /
getEmbeddedManagerOrNull() return null pre-init for callers that want to
detect the uninitialized state explicitly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@franco-zalamena-iterable franco-zalamena-iterable linked an issue Jul 10, 2026 that may be closed by this pull request
* usage error. Use [IterableApi.getEmbeddedManagerOrNull] to detect this state explicitly.
*/
internal class EmptyEmbeddedManager : IterableEmbeddedManager() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmptyInAppManager defines its own private static final String TAG = "EmptyInAppManager";, while this EmptyEmbeddedManager does not.
This means that a pre-init error on the embedded side will get tagged with the base IterableEmbeddedManager tag, while one in the in-app side will get tagged with the easier to find EmptyInAppManager.
Suggest adding an EmptyEmbeddedManager tag constant for consistency.

Suggested change
private const val TAG = "EmptyEmbeddedManager"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RunTime Exceptions are NOT documented

2 participants