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

ConcurrentModificationException in RxJavaPlugins.getPluginImplementationViaProperty #3749

Closed
niqo01 opened this issue Mar 11, 2016 · 6 comments

Comments

@niqo01
Copy link

niqo01 commented Mar 11, 2016

I am using RxJava 1.1.1 on Android and getting the following error:

Caused by java.util.ConcurrentModificationException
       at java.util.Hashtable$HashIterator.nextEntry(Hashtable.java:727)
       at java.util.Hashtable$EntryIterator.next(Hashtable.java:778)
       at java.util.Hashtable$EntryIterator.next(Hashtable.java:776)
       at rx.plugins.RxJavaPlugins.getPluginImplementationViaProperty(RxJavaPlugins.java:177)
       at rx.plugins.RxJavaPlugins.getSchedulersHook(RxJavaPlugins.java:232)
       at rx.schedulers.Schedulers.(Schedulers.java)
       at rx.schedulers.Schedulers.(Schedulers.java)

My code is

unreadConversationsServer = unreadConversations;
      final Scheduler.Worker worker = Schedulers.io().createWorker();
      worker.schedule(() -> {
        try {
          computeUnreadUnSyncedConversationCount();
        } catch (Exception e) {
          Timber.e(e, "Error while computing Unread Unsynced Conversation Count");
        }
        worker.unsubscribe();
      });

Full detail here: http://crashes.to/s/4ecb8083b7f

@akarnokd
Copy link
Member

You seem to have something changing System.getProperties() concurrently with the initialization of the plugin.

@artem-zinnatullin
Copy link
Contributor

Ping @niqo01: were you able to fix the problem?

@akarnokd gave most possible reason of the issue, probably some third-party library modifies system properties concurrently (you can debug access to system properties to find that out).

// We can try to clone() properties before iterating over them (it's a Hashtable (ew) which is synchronized almost everywhere but iterating), but personally, I'd like to not do it if possible.

@akarnokd
Copy link
Member

I don't know what kind of map it is thus copying might have the same issue. We could catch the CME and retry the operation with a fresh iterator.

@zsxwing
Copy link
Member

zsxwing commented Mar 29, 2016

clone looks good to me, since it's called only once for each hook. We won't lose any performance after warming up.

I don't know what kind of map it is thus copying might have the same issue. We could catch the CME and retry the operation with a fresh iterator.

According to the javadoc of Properties, I think clone is safe.

Each key and its corresponding value in the property list is a string.
Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are not Strings. The setProperty method should be used instead. If the store or save method is called on a "compromised" Properties object that contains a non- String key or value, the call will fail. Similarly, the call to the propertyNames or list method will fail if it is called on a "compromised" Properties object that contains a non- String key.

@akarnokd
Copy link
Member

@zsxwing Great!

PR welcome.

@akarnokd
Copy link
Member

Closing via #3822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants