Skip to content

Fixing issue with rxjava2/3 based Promise implementations not handling null #13972

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

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

davydotcom
Copy link
Contributor

It can be often the case that a Promise is used for the purposes of asynchronous operations in an isolated thread / persistence interceptor context. These async operations may not even care about a return type because they may be kicking off other error handling behaviors. In the case of the rxjava based implementations, rxjava gets angry when a return is null based and throws several exceptions:

Example:

RxPromiseSpec > Test promise null handling FAILED
    java.lang.NullPointerException: onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.
        at io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:65)
        at org.grails.async.factory.rxjava2.RxPromise$_closure1.doCall(RxPromise.groovy:47)
        at groovy.lang.Closure.call(Closure.java:433)
        at io.reactivex.internal.operators.single.SingleCreate.subscribeActual(SingleCreate.java:39)
        at io.reactivex.Single.subscribe(Single.java:3666)
        at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
        at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:608)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)

This PR resolves this by translating null to a Void object type which allows this to pass through and behave like other Promise implementations.

Copy link
Contributor

@matrei matrei left a comment

Choose a reason for hiding this comment

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

Nice! Added some comments on the tests.

Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

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

Should we remove rxjava1 since we have 2 + 3 now?

@davydotcom
Copy link
Contributor Author

Should we remove rxjava1 since we have 2 + 3 now?

rxjava1 is well beyond end of life, I believe. I'm open for deprecation and maybe future removal or just removal.

@davydotcom davydotcom merged commit d21ebe8 into 7.0.x Jan 15, 2025
9 of 20 checks passed
@davydotcom davydotcom deleted the patch-grailsasync-rxjava-null branch January 15, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants