Skip to content

Commit 5c83b50

Browse files
hluhovskyiakarnokd
authored andcommitted
Fix NPE when debouncing empty source (#6560)
1 parent 67b9cf6 commit 5c83b50

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/main/java/io/reactivex/internal/operators/flowable/FlowableDebounce.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ public void onComplete() {
119119
if (!DisposableHelper.isDisposed(d)) {
120120
@SuppressWarnings("unchecked")
121121
DebounceInnerSubscriber<T, U> dis = (DebounceInnerSubscriber<T, U>)d;
122-
dis.emit();
122+
if (dis != null) {
123+
dis.emit();
124+
}
123125
DisposableHelper.dispose(debouncer);
124126
downstream.onComplete();
125127
}

src/main/java/io/reactivex/internal/operators/observable/ObservableDebounce.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public void onComplete() {
112112
if (d != DisposableHelper.DISPOSED) {
113113
@SuppressWarnings("unchecked")
114114
DebounceInnerObserver<T, U> dis = (DebounceInnerObserver<T, U>)d;
115-
dis.emit();
115+
if (dis != null) {
116+
dis.emit();
117+
}
116118
DisposableHelper.dispose(debouncer);
117119
downstream.onComplete();
118120
}

src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,14 @@ public void timedError() {
546546
.test()
547547
.assertFailure(TestException.class);
548548
}
549+
550+
@Test
551+
public void debounceOnEmpty() {
552+
Flowable.empty().debounce(new Function<Object, Publisher<Object>>() {
553+
@Override
554+
public Publisher<Object> apply(Object o) {
555+
return Flowable.just(new Object());
556+
}
557+
}).subscribe();
558+
}
549559
}

src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,4 +504,14 @@ public void timedError() {
504504
.test()
505505
.assertFailure(TestException.class);
506506
}
507+
508+
@Test
509+
public void debounceOnEmpty() {
510+
Observable.empty().debounce(new Function<Object, ObservableSource<Object>>() {
511+
@Override
512+
public ObservableSource<Object> apply(Object o) {
513+
return Observable.just(new Object());
514+
}
515+
}).subscribe();
516+
}
507517
}

0 commit comments

Comments
 (0)