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

3.x Fix NPE when debouncing empty source #6559

Merged

Conversation

hluhovskyi
Copy link
Contributor

Background Related issue #6558

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"`

@hluhovskyi hluhovskyi changed the title Fix NPE when debouncing empty source 3.x Fix NPE when debouncing empty source Jul 4, 2019
@akarnokd akarnokd added this to the 3.0 milestone Jul 4, 2019
@codecov
Copy link

codecov bot commented Jul 4, 2019

Codecov Report

Merging #6559 into 3.x will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x    #6559      +/-   ##
============================================
- Coverage     98.16%   98.13%   -0.03%     
- Complexity     6198     6199       +1     
============================================
  Files           682      682              
  Lines         45459    45461       +2     
  Branches       6288     6290       +2     
============================================
- Hits          44626    44615      -11     
- Misses          275      288      +13     
  Partials        558      558
Impacted Files Coverage Δ Complexity Δ
.../internal/operators/flowable/FlowableDebounce.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...ernal/operators/observable/ObservableDebounce.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...l/operators/observable/ObservableFlatMapMaybe.java 84.96% <0%> (-6.54%) 2% <0%> (ø)
.../operators/flowable/FlowableBlockingSubscribe.java 93.02% <0%> (-4.66%) 10% <0%> (-1%)
...nternal/operators/parallel/ParallelReduceFull.java 91.08% <0%> (-3.97%) 2% <0%> (ø)
...ernal/operators/flowable/FlowableFlatMapMaybe.java 88.88% <0%> (-1.94%) 2% <0%> (ø)
...perators/single/SingleFlatMapIterableFlowable.java 95.83% <0%> (-1.67%) 2% <0%> (ø)
...tivex/internal/operators/single/SingleTimeout.java 98.33% <0%> (-1.67%) 2% <0%> (ø)
...perators/mixed/ObservableConcatMapCompletable.java 98.49% <0%> (-1.51%) 3% <0%> (ø)
...internal/operators/flowable/FlowableSwitchMap.java 95.28% <0%> (-1.42%) 3% <0%> (ø)
... and 18 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 b40a892...4c644de. Read the comment docs.

@akarnokd akarnokd merged commit 71945f3 into ReactiveX:3.x Jul 5, 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