Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchMethodError: No static method removeIf #923

Closed
kplanz opened this issue Oct 5, 2021 · 6 comments · Fixed by #924
Closed

NoSuchMethodError: No static method removeIf #923

kplanz opened this issue Oct 5, 2021 · 6 comments · Fixed by #924
Labels
bug Something isn't working

Comments

@kplanz
Copy link

kplanz commented Oct 5, 2021

Describe the bug
We use Coil indirectly via https://github.com/GetStream/stream-chat-android and we are seeing lots of crashes with that exception:

Fatal Exception: java.lang.NoSuchMethodError: No static method removeIf(Ljava/util/Collection;Lj$/util/function/Predicate;)Z in class Lj$/util/Collection$-EL; or its super classes (declaration of 'j$.util.Collection$-EL' appears in base.apk!classes2.dex)
       at coil.memory.RealWeakMemoryCache.cleanUp$coil_base_release(WeakMemoryCache.kt:173)

Since Stream could not help us with this so far, we are reaching out to you. We cannot reproduce the crash consistently, but for some users it happens quite often.

This looks like some Java 8 issue since this method is new in Java 8. We have enabled Java 8 compatibility in our project and Stream has it also in their SDK.

Excerpt from our build.gradle:

compileOptions {
    coreLibraryDesugaringEnabled true
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}

And from the Stream SDK: https://github.com/GetStream/stream-chat-android/blob/4.19.0/stream-chat-android-core/build.gradle#L18

So if you have any ideas what is happening here, we would really appreciate it. Thank you!

Logs/Screenshots

Fatal Exception: java.lang.NoSuchMethodError: No static method removeIf(Ljava/util/Collection;Lj$/util/function/Predicate;)Z in class Lj$/util/Collection$-EL; or its super classes (declaration of 'j$.util.Collection$-EL' appears in base.apk!classes2.dex)
       at coil.memory.RealWeakMemoryCache.cleanUp$coil_base_release(WeakMemoryCache.kt:173)
       at coil.memory.RealWeakMemoryCache.trimMemory(WeakMemoryCache.kt:145)
       at coil.RealImageLoader.onTrimMemory(RealImageLoader.kt:205)
       at coil.util.SystemCallbacks.onTrimMemory(SystemCallbacks.kt:46)
       at android.app.Application.onTrimMemory(Application.java:306)
       at android.app.ActivityThread.handleTrimMemory(ActivityThread.java:6956)
       at android.app.ActivityThread.access$1300(ActivityThread.java:301)
       at android.app.ActivityThread$ApplicationThread.lambda$scheduleTrimMemory$0(ActivityThread.java:1792)
       at android.app.-$$Lambda$ActivityThread$ApplicationThread$tUGFX7CUhzB4Pg5wFd5yeqOnu38.accept(:8)
       at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:278)
       at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:201)
       at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1010)
       at android.view.Choreographer.doCallbacks(Choreographer.java:809)
       at android.view.Choreographer.doFrame(Choreographer.java:746)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:995)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8595)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Version
1.2.1 and 1.3.2 (we tried different Stream SDK versions).
Seems to happen mainly on Samsung devices.

@kplanz kplanz added the bug Something isn't working label Oct 5, 2021
@colinrtwhite
Copy link
Member

colinrtwhite commented Oct 5, 2021

Hmm do you know if the crashes occur on a specific Android version? We only use the method on API 24 (which has initial Java 8 support on Android without desugaring) and above, but we could increase that to work-around device-specific issues.

It's likely mostly occurring on Samsung devices since they're the most common Android devices.

EDIT: I ended up removing the use of removeIf since it isn't super necessary and it's probably better to use a consistent algorithm across all API levels.

@colinrtwhite
Copy link
Member

This looks like it might be a desugaring bug of some kind unrelated to Coil. Your stack trace mentions j$/util/Collection$-EL which contains the desugared code for Collection methods. However, Coil's usage of removeIf shouldn't be desugared since Java 8 support exists on API 24 and above. I would try setting coreLibraryDesugaringEnabled to false if it's not needed (it's not needed for Coil).

@kplanz
Copy link
Author

kplanz commented Oct 6, 2021

Nice, thank you for the quick reaction!

We will try set coreLibraryDesugaringEnabled to false and see if the issue still occurs (I think we tried that already and still had the crash, but will check again).

@zsmb13
Copy link

zsmb13 commented Oct 6, 2021

@colinrtwhite Do you have an expected date for the next Coil release that will contain the fix for this issue?

@colinrtwhite
Copy link
Member

colinrtwhite commented Oct 6, 2021

@zsmb13 It should be out pretty soon, but I can't give an ETA. If you need the fix now, you should use the latest snapshot.

Also I still think this is a local desugaring issue as we use coreLibraryDesugaringEnabled=true at Instacart and don't experience this crash.

@colinrtwhite
Copy link
Member

@zsmb13 Actually main's in a good state for a release so I just pushed 1.4.0 which contains the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants