amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
27 stars 10 forks source link

Calling setUserId with invalid character crashes app #196

Closed rkrishnan2012 closed 1 month ago

rkrishnan2012 commented 1 month ago

Expected Behavior

1) Call amplitude.setUserId("hello@email.com") 2) Expect the app to not crash

Current Behavior

The app crashes with stacktrace:

java.io.IOException: Could not create directory at /tmp/amplitude-identity/$default_instance
at com.amplitude.id.utilities.FileUtilsKt.createDirectory(FileUtils.kt:9)
at com.amplitude.id.FileIdentityStorage.<init>(FileIdentityStorage.kt:21)
at com.amplitude.id.FileIdentityStorageProvider.getIdentityStorage(FileIdentityStorage.kt:71)
at com.amplitude.core.Amplitude$build$built$1.invokeSuspend(Amplitude.kt:112)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@5de282a, java.util.concurrent.ThreadPoolExecutor@a50161b[Running, pool size = 2, active threads = 1, queued tasks = 0, completed tasks = 2]]

Possible Solution

Not really sure.

Steps to Reproduce

Call amplitude.setUserId("hello@email.com") after initializing the Amplitude class.

Environment

rkrishnan2012 commented 1 month ago

Actually this issue happens because I imported com.amplitude.core.Amplitude instead of com.amplitude.android.Amplitude. Fixing the import resolved my issue.