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

2.x Fix NPE when debouncing empty source #6560

Merged

Conversation

hluhovskyi
Copy link
Contributor

Background Related issue #6558
Cherry pick of #6559 for 2.x version

Debounce with selector on the empty Observable leads to NPE.

It happens because of DebounceObserver#debouncer field is set up only when onNext is called. When onNext isn't called at all, like when debouncing Observable.empty(), we get a null reference from debouncer and call emit on null which actually leads to NPE.

Change
Wrap emit call with null check both in ObservableDebounce and FlowableDebounce

Test plan
To check Observable:

./gradlew test --tests "io.reactivex.internal.operators.observable.ObservableDebounceTest.debounceOnEmpty"`

To check Flowable:

./gradlew test --tests "io.reactivex.internal.operators.flowable.FlowableDebounceTest.debounceOnEmpty"`

@codecov
Copy link

codecov bot commented Jul 4, 2019

Codecov Report

Merging #6560 into 2.x will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6560      +/-   ##
============================================
- Coverage     98.25%   98.24%   -0.02%     
- Complexity     6334     6337       +3     
============================================
  Files           677      677              
  Lines         45486    45488       +2     
  Branches       6319     6321       +2     
============================================
- Hits          44691    44688       -3     
- Misses          249      252       +3     
- Partials        546      548       +2
Impacted Files Coverage Δ Complexity Δ
.../internal/operators/flowable/FlowableDebounce.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...ernal/operators/observable/ObservableDebounce.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...ernal/operators/flowable/FlowableFlatMapMaybe.java 88.88% <0%> (-5.8%) 2% <0%> (ø)
...nternal/operators/parallel/ParallelReduceFull.java 91.08% <0%> (-3.97%) 2% <0%> (ø)
.../operators/observable/ObservableFlatMapSingle.java 88.8% <0%> (-2.99%) 2% <0%> (ø)
...tivex/internal/schedulers/TrampolineScheduler.java 96.1% <0%> (-2.6%) 6% <0%> (ø)
...ternal/operators/completable/CompletableMerge.java 96.42% <0%> (-2.39%) 2% <0%> (ø)
...ernal/operators/flowable/FlowableFromIterable.java 94.11% <0%> (-2.14%) 5% <0%> (ø)
...nternal/operators/observable/ObservableWindow.java 98% <0%> (-2%) 3% <0%> (ø)
...x/internal/operators/flowable/FlowablePublish.java 96.65% <0%> (-1.68%) 13% <0%> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67b9cf6...030c253. Read the comment docs.

@akarnokd akarnokd merged commit 5c83b50 into ReactiveX:2.x Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants