[SDK-417] Fail gracefully when managers accessed before init#1073
Merged
franco-zalamena-iterable merged 2 commits intoJul 14, 2026
Conversation
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>
rtlsilva
reviewed
Jul 10, 2026
Pre-init errors from the embedded no-op stub were logged under the inherited base tag "IterableEmbeddedManager" instead of a stub-specific tag, unlike EmptyInAppManager which uses its own "EmptyInAppManager" tag. Add a LOG_TAG constant so both stubs log under a findable, consistent name. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
joaodordio
approved these changes
Jul 14, 2026
joaodordio
left a comment
Member
There was a problem hiding this comment.
Nice fix, this catches up nicely with the Swift SDK's EmptyInAppManager / EmptyEmbeddedManager pattern and also quietly resolves the process-death recovery crash in IterableInAppFragmentHTMLNotification where the fragment could re-hydrate before Application#onCreate re-initializes the SDK.
Approving, with a few small non blockers worth considering before merge:
- Log noise: the empty stubs log an error on every method call, plus the getter also logs. In a render loop before init this gets loud fast. Consider logging once at the getter and either dropping the per-method logs or dropping them to
IterableLogger.d. - Debug assertion parity with iOS: Swift pairs the empty return with
assertionFailure, which crashes debug builds and no-ops in release. ABuildConfig.DEBUGguarded throw ingetInAppManager()/getEmbeddedManager()would give devs the same fail-fast signal locally while keeping prod crash-safe. This is standard operation in iOS world, not sure about Android. - Post-init coverage: worth adding two tests that call
IterableApi.initialize(...)and assert both getters return the real managers (notinstanceof Empty*) and*OrNullreturn non-null. Locks in the wiring flip. - Failure-handler contract test:
EmptyInAppManager.setRead(msg, read, success, failure)andremoveMessage(..., success, failure)invokefailureHandler.onFailure("Iterable SDK is not initialized", null). That's an observable contract, cheap to lock down with a test. - Parent-class safety note: a short comment on
IterableInAppManagerandIterableEmbeddedManagersaying "any new method must be overridden in the Empty* subclass or must not touchapi/context/iterableApi" would help future contributors avoid landmines, especially with the newlateinitfields. getMessages(placementId)parity: iOS returns[], Android's empty stub returnsnull(mirrors the pre-existing nullable signature). Not from this PR, but returningemptyList()here would soften it without touching the public type.- Migration guide nit: worth a one-liner that if anyone was catching
RuntimeExceptionfrom these getters to detect the uninitialized state, they should switch to the new*OrNullvariants.
None of these are blockers, ship it whenever.
Contributor
Author
|
I like the idea of crashing on debug and just no-op on production. But the problem is that the BuildConfig.Debug references the sdk BuildConfig from what i saw, so this would be just ignored in the final version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔹 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.