android-cookie-store icon indicating copy to clipboard operation
android-cookie-store copied to clipboard

Convert uriIndex cookies to a list before processing

Open vicky7230 opened this issue 2 months ago • 0 comments

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)

vicky7230 avatar Dec 05 '25 10:12 vicky7230