WalletConnectKotlinV2 icon indicating copy to clipboard operation
WalletConnectKotlinV2 copied to clipboard

NullPointerException: java.util.LinkedList$ListItr in next

Open mhernand40 opened this issue 2 years ago • 0 comments

Describe the bug Seeing the following stack trace in production

java.lang.NullPointerException: Attempt to read from field 'java.util.LinkedList$Node java.util.LinkedList$Node.next' on a null object reference in method 'java.lang.Object java.util.LinkedList$ListItr.next()'
    at java.util.LinkedList$ListItr.next(LinkedList.java:897)
    at kotlin.collections.CollectionsKt__MutableCollectionsKt.filterInPlace$CollectionsKt__MutableCollectionsKt
    at kotlin.collections.CollectionsKt__MutableCollectionsKt.filterInPlace$CollectionsKt__MutableCollectionsKt
    at kotlin.collections.CollectionsKt__MutableCollectionsKt.filterInPlace$CollectionsKt__MutableCollectionsKt
    at kotlin.collections.CollectionsKt__MutableCollectionsKt.removeAll
    at com.walletconnect.sign.storage.sequence.SessionStorageRepository.deleteSession
    at com.walletconnect.sign.engine.use_case.calls.DisconnectSessionUseCase$disconnect$2.invokeSuspend
    at com.walletconnect.sign.engine.use_case.calls.DisconnectSessionUseCase$disconnect$2.invoke
    at com.walletconnect.sign.engine.use_case.calls.DisconnectSessionUseCase$disconnect$2.invoke
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn
    at kotlinx.coroutines.SupervisorKt.supervisorScope
    at kotlinx.coroutines.SupervisorKt.supervisorScope
    at com.walletconnect.sign.engine.use_case.calls.DisconnectSessionUseCase.disconnect
    at com.walletconnect.sign.engine.domain.SignEngine.disconnect
    at com.walletconnect.sign.client.SignProtocol$disconnect$1.invokeSuspend
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith
    at kotlinx.coroutines.DispatchedTask.run
    at kotlinx.coroutines.DispatchedTask.run
    at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run
    at kotlinx.coroutines.scheduling.TaskImpl.run
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely
    at kotlinx.coroutines.scheduling.Task.getMode$kotlinx_coroutines_core
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run

SDK Version

  • Client: Kotlin
  • Version 1.16.0

To Reproduce N/A

Device (please complete the following information):

  • Device: Pixel 7
  • OS: Android 13
  • Browser: OpenSea App
  • Version 2.26.2

Additional context I took at look at the offending line in SessionStorageRepository.deleteSession. The SDK is reading from/writing to a static global mutable list. I'd strongly recommend avoiding global static mutable state and encapsulating this in some sort of repository for testability reasons as well as maintaining a more thread-safe mutable collection or consider using an immutable collection where new copies are created after a transformation and assigned to either a var in a synchronized/volatile manner or an AtomicReference.

mhernand40 avatar Sep 14 '23 18:09 mhernand40