-
Notifications
You must be signed in to change notification settings - Fork 226
Closed
Labels
Description
Hi. I was asked to review the library's RxJava 2 usage for potential logical or concurrency issues.
Review @ commit: 0147484b
Main issues:
- AutoDisposingCompletableObserverImpl.java#L45: The
DisposableMaybeObservercould be created andsetOnce'd before the call tolifecycle.subscribe(). - AutoDisposingCompletableObserverImpl.java#L52: The
mainDisposablecould be already set and thedelegatecurrently executing one of itsonXXXmethods which violates the contract unless it is guaranteed both the lifecycle signal and the onXXX calls happen on the same thread (i.e., forcedobserveOn(AndroidSchedulers.mainThread())). Possible solution: always calldelegate.onSubscribe(this)first, mutually exclude the onXXX signals via anAtomicBoolean once. - AutoDisposingCompletableObserverImpl.java#L58: May not be a good idea to leave the delegate non-terminated in this case, if the lifecycle actually can get
onComplete. - AutoDisposingCompletableObserverImpl.java#L73:
synchronizedis pointless here. - AutoDisposingCompletableObserverImpl.java#L80:
synchronizedis pointless here. If the purpose was to mutually exclude with#L73then it is not worth it. IflazySetwins thendispose(ref)will do nothing, if they race, both cases could win probabilistically. - AutoDisposingMaybeObserverImpl.java: Same problems as with the
CompletableObserverimplementation. - AutoDisposingObserverImpl.java: Same problems as with the
CompletableObserverimplementation. Here one would need aHalfSerializerto mutually exclude the onXXX events (as there could be multipleonNextcalls). - AutoDisposingSingleObserverImpl.java: Same problems as with the
CompletableObserverimplementation. - AutoDisposingSubscriberImpl.java: Same problems as with the
CompletableObserverimplementation and then some. - AutoDisposingSubscriberImpl.java#L80: There is no
onStartprovided by the API and thedelegate.onSubscribeis called aftermainSubscriptionis definitely set: the null check should always pass and thus unnecessary. Note though that if one does thesetOnce(mainSubscription)before the lifecycle is attached, one may need to use deferred requesting to not trigger the upstream emission while the code is setting up other things inonSubscribe. - ViewAttachEventsObservable.java#L41 If the call is not on the main thread,
onSubscribeis not called which can lead to aNullPointerExceptionin the dowstream. The no-opDisposableshould be sent to theObserverfirst. - ViewAttachEventsObservable.java#L51: The
Observermay cancel immediately and since the listener is not registered with theviewyet, it won't get removed but then added unconditionally. Assuming the events also come from the main thread, one could add the listener first, and callonSubscribenext. If adding the listener triggers an event emission immediately, keep the current order and after adding the listener, check if the listener has been disposed in the meantime and remove the listener. - LifecycleEventsObservable.java#L78: Same problems as with the
ViewAttachEventsObservable.
Minor issues:
- AutoDisposingCompletableObserver.java#L30: missing space in
forintrospection. - AutoDisposingObserver.java#L30: missing tailing
sfrompurpose? - AutoDispose.java#L169: class could be
final. - AutoDispose.java#L199: class could be
final. - AutoDispose.java#L229: class could be
final. - AutoDisposePlugins.java#L36: Such lockdown support may not be desirable on Android. The same feature was aimed at server/J2EE container use of RxJava.
- dependencies.gradle#L65: Using a pretty old RxJava 2 version.
Reactions are currently unavailable