Skip to content

Conversation

@vicky7230
Copy link

A ConcurrentModificationException is being thrown when iterating over a list that's being modified simultaneously. The issue is in SharedPreferencesCookieStore.add() at line 56—the uriIndex map is being modified while it's being iterated.

The problem occurs becauseSharedPreferencesCookieStore.add()callssuper.add()which modifies uriIndex, and then immediately tries to iterate over the cookies to serialize them. If another thread is also accessing the same collection, a
concurrent modification exception occurs.

Fix: Create a copy of the cookies list before iterating to avoid concurrent modification issues.

Crash stacktrace:

Fatal Exception: java.util.ConcurrentModificationException:    
       at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1111)    
       at java.util.ArrayList$Itr.next(ArrayList.java:1064)    
       at uΨجЮףλ.tחΡНΖج.sмץלбН.SharedPreferencesCookieStore.add(:56)    
       at java.net.CookieManager.put(CookieManager.java:357)    
       at uΨجЮףλ.tחΡНΖج.sмץלбН.WebKitSyncCookieManager.put(:5)    
       at net.gotev.cookiestore.okhttp.JavaNetCookieJar.saveFromResponse(:75)    
       at okhttp3.internal.http.HttpHeaders.receiveHeaders(HttpHeaders.kt:207)    
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:85)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at com.mttnow.android.gbt.core.network.interceptor.InvalidAppInterceptor.intercept(InvalidAppInterceptor.kt:33)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at com.mttnow.android.gbt.core.network.interceptor.GbtHeaderInterceptor.intercept(GbtHeaderInterceptor.kt:109)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at com.mttnow.android.gbt.core.network.interceptor.LoggerInterceptor.intercept(LoggerInterceptor.kt:16)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at com.mttnow.android.gbt.core.network.interceptor.NetworkConnectionInterceptor.intercept(NetworkConnectionInterceptor.kt:19)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:154)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at com.mttnow.android.gbt.core.network.interceptor.GbtApiVersionInterceptor.intercept(GbtApiVersionInterceptor.kt:45)    
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)    
       at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)    
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)    
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)    
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651)    
       at java.lang.Thread.run(Thread.java:1119)

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.

1 participant