Skip to content

Commit

Permalink
Fix TrampolineScheduler NullPointerException
Browse files Browse the repository at this point in the history
I tried for about 30 minutes to replicate the NPE reported in ReactiveX#1702 but couldn't.
It makes sense reading the code that an unsubscribe could trigger an NPE though so I'm fixing it as per recommendation of @DylanSale even though I can't replicate.
I confirmed that the items are being put in the queue BEFORE the wip variable is incremented, so that concurrency seems okay.
  • Loading branch information
benjchristensen committed Oct 9, 2014
1 parent 69bc312 commit 2cf4349
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/rx/schedulers/TrampolineScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ private Subscription enqueue(Action0 action, long execTime) {

if (wip.getAndIncrement() == 0) {
do {
queue.poll().action.call();
TimedAction polled = queue.poll();
// check for null as it could have been unsubscribed and removed
if (polled != null) {
polled.action.call();
}
} while (wip.decrementAndGet() > 0);
return Subscriptions.empty();
} else {
Expand Down

0 comments on commit 2cf4349

Please sign in to comment.