Skip to content

Replace RuntimeException with graceful handling when SDK not initialized#1023

Closed
franco-zalamena-iterable wants to merge 1 commit intomasterfrom
fix/727-graceful-uninitialized-error
Closed

Replace RuntimeException with graceful handling when SDK not initialized#1023
franco-zalamena-iterable wants to merge 1 commit intomasterfrom
fix/727-graceful-uninitialized-error

Conversation

@franco-zalamena-iterable
Copy link
Copy Markdown
Contributor

@franco-zalamena-iterable franco-zalamena-iterable commented Apr 7, 2026

Summary

  • Replace undocumented RuntimeExceptions with logged warnings and null returns
  • SDK methods now fail gracefully when called before initialization

Test plan

  • Call getInAppManager() before initialization - should log warning, not crash
  • Call getInAppManager() after initialization - should work normally
  • Verify other similar methods also handle gracefully

🤖 Generated with Claude Code

getInAppManager() and getEmbeddedManager() now log an error and return
null instead of throwing an undocumented RuntimeException when called
before IterableApi is initialized. Annotations updated from @nonnull
to @nullable accordingly.

Fixes #727

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@franco-zalamena-iterable
Copy link
Copy Markdown
Contributor Author

PR Analysis

Problem: Calling getInAppManager() or getEmbeddedManager() before SDK initialization throws an undocumented RuntimeException, crashing the app. The user requests graceful failure with a log message instead.

Ideal fix plan:

  • Replace RuntimeException with an error log in getInAppManager() and getEmbeddedManager()
  • Return @Nullable and update annotation accordingly
  • Guard all internal call sites that chain methods on the return value (e.g., getInAppManager().syncInApp(), getInAppManager().getMessageById(...), getEmbeddedManager().syncMessages()) with null checks to prevent NullPointerException
  • Add unit tests that call these methods before initialization and verify no crash occurs
  • Consider the same pattern for any other public methods that throw undocumented RuntimeException

What the PR did:

  • Replaced RuntimeException with IterableLogger.e() + return null in both getInAppManager() and getEmbeddedManager()
  • Changed @NonNull to @Nullable on both methods

Assessment:

  • Root cause identified: yes — the RuntimeException on uninitialized access is the root cause
  • Fix correctness: partially correct — the two methods themselves are fixed, but the change introduces new NullPointerException crashes at every internal call site that chains on the result
  • Missed:
    • Critical: At least 7 internal call sites now crash with NPE instead of RuntimeException. Examples: getInAppManager().syncInApp() (line ~479), getEmbeddedManager().syncMessages() (line ~480), getInAppManager().getMessageById(messageId) (lines ~1301, 1317, 1859, 1876, 1907). Each of these needs a null check or early return.
    • No tests were added. At minimum, tests should verify that calling getInAppManager() and getEmbeddedManager() before initialization returns null without crashing, and that downstream public methods like inAppConsume() also handle the null gracefully.
  • Wrong assessment: none — the direction is correct, the execution is incomplete
  • Tests: needed but missing

@franco-zalamena-iterable franco-zalamena-iterable deleted the fix/727-graceful-uninitialized-error branch April 8, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant