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

Fixed concurrent modifications in UI components when subscribing taken events #162

Closed
wants to merge 4 commits into from
Closed

Fixed concurrent modifications in UI components when subscribing taken events #162

wants to merge 4 commits into from

Conversation

jmatsu
Copy link

@jmatsu jmatsu commented Apr 26, 2015

This fixes ConcurrentModificationException which is thrown by Observables that invoked Observable#take(int).

Relevant issue is #158 .

@@ -75,7 +75,7 @@ public boolean removeOnClickListener(final View.OnClickListener listener) {

@Override
public void onClick(final View view) {
for (final View.OnClickListener listener : listeners) {
for (final View.OnClickListener listener: new ArrayList<View.OnClickListener>(listeners)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is extremely wasteful. Try a CopyOnWriteArrayList for listeners instead?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the reasonable comment.
I modified the codes to match it, and pushed them.

@ronshapiro
Copy link
Contributor

Did you find out when/how the list of listeners is being modified from a background thread?

@jmatsu
Copy link
Author

jmatsu commented Apr 27, 2015

I did.
This is not caused by modifications from two or more threads.

In this case, a taken (and completed) observer will try to unsubscribe events on UiThread after invoking onNext(View).
But List#remove via unsubscribing is sequentially executed because onNext(View) is called from UiThread.

So the solution is using CopyOnWriteArrayList or to create new list, I think.

@@ -75,7 +76,7 @@ public boolean removeOnClickListener(final View.OnClickListener listener) {

@Override
public void onClick(final View view) {
for (final View.OnClickListener listener : listeners) {
for (final View.OnClickListener listener: listeners) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert all of these small whitespace changes, unnecessary usages of final?

Copy link
Author

Choose a reason for hiding this comment

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

@ronshapiro I see. Minimized diffs.

@passsy
Copy link

passsy commented May 19, 2015

+1

@JakeWharton
Copy link
Contributor

This is fixed in https://github.com/JakeWharton/RxBinding but per #172 this won't be going into RxAndroid core. We have removed the view binding observables for the next release.

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.

4 participants