Skip to content

Fatal Exception: java.util.ConcurrentModificationException #222

@tintil

Description

@tintil

New Issue Checklist

  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Device Info Xiaomi Redmi Note9, Samsung Galaxy A7, etc..
System Version 8.0-14.0
APNG4Android Library Version 2.28.0
Repro rate sometimes
Repro with our demo project -
Demo project link -

Issue Description and Steps

We get the following exception in our project from time to time. It seems to happen when stop and unregisterAnimationCallback are called close to one another.

My guess is that https://github.com/penfeizhou/APNG4Android/blob/master/frameanimation/src/main/java/com/github/penfeizhou/animation/FrameAnimationDrawable.java#L60 is still not safe since copying over a set to an array most likely involves an iteration. Which can cause an exception if the set is modified at the same time.

I can try to write a demo project which reproduces the exception if necessary.

       Fatal Exception: java.util.ConcurrentModificationException:
       at java.util.HashMap$HashIterator.nextNode(HashMap.java:1441)
       at java.util.HashMap$KeyIterator.next(HashMap.java:1465)
       at java.util.AbstractCollection.finishToArray(AbstractCollection.java:232)
       at java.util.AbstractCollection.toArray(AbstractCollection.java:143)
       at java.util.ArrayList.<init>(ArrayList.java:191)
       at com.github.penfeizhou.animation.FrameAnimationDrawable$1.handleMessage(FrameAnimationDrawable.java:60)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7366)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions