facebook-android-sdk icon indicating copy to clipboard operation
facebook-android-sdk copied to clipboard

Fatal Exception: java.util.ConcurrentModificationException:

Open JhinSir opened this issue 5 months ago • 1 comments

Checklist before submitting a bug report

Java version

JDK11

Android version

Android13,14,12,10,11

Android SDK version

16.2.0

Installation platform & version

Gradle

Package

Core & AppEvents

Goals

The program is normal

Expected results

No crash

Actual results

Program startup crashes Fatal Exception: java.util.ConcurrentModificationException: at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:760) at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:782) at com.facebook.internal.FetchedAppGateKeepersManager.getGateKeepersForApplication(FetchedAppGateKeepersManager.kt:165) at com.facebook.internal.FetchedAppGateKeepersManager.getGateKeeperForKey(FetchedAppGateKeepersManager.kt:177) at com.facebook.internal.FeatureManager.getGKStatus(FeatureManager.kt:107) at com.facebook.internal.FeatureManager.isEnabled(FeatureManager.kt:54) at com.facebook.internal.FeatureManager.isEnabled(FeatureManager.kt:54) at com.facebook.internal.Utility.setAppEventAttributionParameters(Utility.kt:578) at com.facebook.applinks.AppLinkData.fetchDeferredAppLinkFromServer(AppLinkData.java:143) at com.facebook.applinks.AppLinkData.access$000(AppLinkData.java:36) at com.facebook.applinks.AppLinkData$1.run(AppLinkData.java:131) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012)

Steps to reproduce

Unable to reproduce

Code samples & details

After integrating the SDK, calling the AppLinkData.fetchDeferredAppLinkData method in the Application's oncreate method, 5K+ crashes were observed on firbase. However, the crash cannot be reproduced locally.
The following is my debugging process:
1. Because I called AppLinkData.fetchDeferredAppLinkData in the Kotlin coroutine, I am not sure whether there is an asynchronous concurrency problem in a multi-threaded environment
2. The FetchedAppGateKeepersManager class in the source code, the following code:
      val output: MutableMap<String, Boolean> = HashMap()
      val jsonObject: JSONObject = fetchedAppGateKeepers[applicationId] ?: JSONObject()
      val jsonIterator = jsonObject.keys()
      while (jsonIterator.hasNext()) {
        val key = jsonIterator.next()
        output[key] = jsonObject.optBoolean(key)
      }
Printing the log, I found that even when multiple threads accessed and modified at the same time, it did not affect the iteration here. So I am wondering what other possible points may cause this error?
3.Is it possible that cacheList is empty under certain circumstances? Is it possible that the SDK initialization and the AppLinkData.fetchDeferredAppLinkData method are executed simultaneously under certain extreme conditions when the App is started?

JhinSir avatar Aug 30 '24 03:08 JhinSir