Skip to content

Fix the way to remove unsubscribed channels to avoid ConcurrentModificationException#8

Merged
genert merged 1 commit into
ninjasolutions:masterfrom
kikuchy:fix_concurrent_modification
Aug 14, 2021
Merged

Fix the way to remove unsubscribed channels to avoid ConcurrentModificationException#8
genert merged 1 commit into
ninjasolutions:masterfrom
kikuchy:fix_concurrent_modification

Conversation

@kikuchy
Copy link
Copy Markdown
Contributor

@kikuchy kikuchy commented Dec 20, 2020

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Bug fix

⤵️ What is the current behavior?

Pusher.init() on Android will cause ConcurrentModificationException when the app will be Hot Restarted.

It comes from the removing Iterator elements in for-in statement.
e.g.) https://stackoverflow.com/questions/18448671/how-to-avoid-concurrentmodificationexception-while-removing-elements-from-arr/18448699

To avoid that, I move the deletion of channels to after the for-in statement of init().

🆕 What is the new behavior (if this is a feature change)?

No new behavior.

💥 Does this PR introduce a breaking change?

No.

🐛 Recommendations for testing

📝 Links to relevant issues/docs

Stack trace about the bug. You can see it when you hot restart the app on Android.

I/flutter (22977): PlatformException(error, null, null, java.util.ConcurrentModificationException
I/flutter (22977):  at java.util.HashMap$HashIterator.nextNode(HashMap.java:1441)
I/flutter (22977):  at java.util.HashMap$EntryIterator.next(HashMap.java:1475)
I/flutter (22977):  at java.util.HashMap$EntryIterator.next(HashMap.java:1473)
I/flutter (22977):  at com.ninjasolutions.pusher.PusherPlugin.init(PusherPlugin.java:117)
I/flutter (22977):  at com.ninjasolutions.pusher.PusherPlugin.onMethodCall(PusherPlugin.java:86)
I/flutter (22977):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
I/flutter (22977):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
I/flutter (22977):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
I/flutter (22977):  at android.os.MessageQueue.nativePollOnce(Native Method)
I/flutter (22977):  at android.os.MessageQueue.next(MessageQueue.java:326)
I/flutter (22977):  at android.os.Looper.loop(Looper.java:160)
I/flutter (22977):  at android.app.ActivityThread.main(ActivityThread.java:6669)
I/flutter (22977):  at java.lang.reflect.Method.invoke(Native Method)
I/flutter (22977):  at com.android.internal.os.RuntimeInit$MethodAndArgsCal
I/flutter (22977): 
I/flutter (22977): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
I/flutter (22977): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
I/flutter (22977): <asynchronous suspension>
I/flutter (22977): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
I/flutter (22977): #3      Pusher.init (package:flutter_pusher/pusher.dart:49:20)

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current develop

Copy link
Copy Markdown
Collaborator

@genert genert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@genert genert merged commit c59b6b3 into ninjasolutions:master Aug 14, 2021
@kikuchy kikuchy deleted the fix_concurrent_modification branch August 15, 2021 14:07
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.

2 participants