Skip to content

Fix lateinit bug#141

Merged
ren6 merged 3 commits intomasterfrom
FixLateinitBug
Feb 5, 2026
Merged

Fix lateinit bug#141
ren6 merged 3 commits intomasterfrom
FixLateinitBug

Conversation

@aaudin90
Copy link
Collaborator

  • Fix UninitializedPropertyAccessException crash when SDK methods are called before full initialization
  • Changed lateinit var userId and deviceId to nullable types with proper null checks
  • Cancel coroutine scopes on clear() to prevent race conditions
  • Generate fallback UUID when userId is null in fallback mode
  • Replace CoroutineExceptionHandler with explicit runCatchingCancellable blocks for better error handling

@ren6
Copy link
Contributor

ren6 commented Jan 26, 2026

@aaudin90 please add safety checks for subscriptions() and nonRenewingPurchases() methods

aaudin90 and others added 3 commits January 30, 2026 00:33
…error handling

Changed lateinit var userId and deviceId to nullable types to prevent
UninitializedPropertyAccessException when SDK methods are called before
initialization completes.

Key changes:
- userId and deviceId are now nullable with explicit null checks
- isInitialized() checks for null instead of ::isInitialized
- clear() cancels coroutine scopes and resets userId/deviceId to null
- Public userId() and deviceId() methods return nullable types
- Added null checks with ApphudError in RequestManager, PurchaseBodyFactory,
  RegistrationBodyFactory, and RegistrationProvider
- Fallback mode generates UUID if userId is null
- Added safety checks to subscriptions() and nonRenewingPurchases()

Replaced CoroutineExceptionHandler with explicit runCatchingCancellable blocks
for better error handling and proper CancellationException propagation:
- Removed global errorHandler pattern
- Wrapped coroutine code in runCatchingCancellable with explicit onFailure logging
- Simplified toApphudError() extension function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added ApphudInternal.userId setup in ApphudHasPremiumAccessTest to simulate
initialized SDK state. Tests that expect active subscriptions or purchases
now set userId before calling hasPremiumAccess().

Added userId cleanup in tearDown() to ensure test isolation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added instruction to generate commit messages based strictly on actual
diffs rather than copying old commit messages. This ensures accurate
descriptions when restructuring commits.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ren6 ren6 merged commit e5ff6a6 into master Feb 5, 2026
2 checks passed
@ren6 ren6 deleted the FixLateinitBug branch February 5, 2026 09:00
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.

2 participants