Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Reset crashes if called before async build completes
- Added guard to check isBuilt.isCompleted before calling androidContextPlugin.initializeDeviceId(), with fallback to direct setDeviceId() call when build is incomplete.
Or push these changes by commenting:
@cursor push 8015690ab3
Preview (8015690ab3)
diff --git a/android/src/main/java/com/amplitude/android/Amplitude.kt b/android/src/main/java/com/amplitude/android/Amplitude.kt
--- a/android/src/main/java/com/amplitude/android/Amplitude.kt
+++ b/android/src/main/java/com/amplitude/android/Amplitude.kt
@@ -128,7 +128,11 @@
override fun reset(): Amplitude {
setUserId(null)
- androidContextPlugin.initializeDeviceId(configuration as Configuration, forceRegenerate = true)
+ if (isBuilt.isCompleted) {
+ androidContextPlugin.initializeDeviceId(configuration as Configuration, forceRegenerate = true)
+ } else {
+ setDeviceId(ContextPlugin.generateRandomDeviceId())
+ }
return this
}|
|
||
| override fun reset(): Amplitude { | ||
| setUserId(null) | ||
| if (isBuilt.isCompleted) { |
There was a problem hiding this comment.
Reset crashes if called before async build completes
High Severity
The old reset() guarded against calling androidContextPlugin.initializeDeviceId() before the build completed by checking isBuilt.isCompleted and falling back to setDeviceId(ContextPlugin.generateRandomDeviceId()). That guard is now removed. Since androidContextPlugin has a lateinit var amplitude that is only set during setup() (called when the plugin is added to the timeline in buildInternal()), calling reset() before the async build completes will throw an UninitializedPropertyAccessException. Every code path through initializeDeviceId() calls setDeviceId(), which accesses amplitude.



Describe what this PR is addressing
Describe the solution
Steps to verify the change
Useful links and documentation (optional)
Checklist
Note
Medium Risk
Concurrency/initialization ordering changes (removing
isBuilt.await()and moving work tostorageIODispatcher) could surface race conditions in event/session processing or storage/migration timing, though the changes are localized and covered by updated tests.Overview
Shifts SDK coroutine execution away from
amplitudeDispatcherby deprecating it in core, removing it from the Android wrapper/test helpers, and running corebuild()andflush()onstorageIODispatcherinstead.Removes several
isBuilt.await()gates (AndroidTimeline.start,DefaultEventUtilsstorage writes, coreflush) and simplifies Androidreset()to always regenerate the device ID viaAndroidContextPlugin. Also makesAndroidContextPluginlazily initialize itsAndroidContextProvideron first use and cleans up a few minor Kotlin style issues.Written by Cursor Bugbot for commit c8f7209. This will update automatically on new commits. Configure here.