Skip to content

fix: ensure no NPE is thrown with SerializedFluxSink #1096

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 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import reactor.core.publisher.Mono;
import reactor.util.context.Context;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

Expand Down Expand Up @@ -95,7 +96,10 @@ private void recurseCursor(){
})
.doOnSuccess(results -> {
if (results != null) {
results.forEach(sink::next);
results
.stream()
.filter(Objects::nonNull)
.forEach(sink::next);
calculateDemand(-results.size());
}
if (batchCursor.isClosed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -328,6 +330,32 @@ public void testBatchCursorDoesNotDropAnError() {
}
}

@Test
@DisplayName("Ensure no NPE is thrown on null in result set")
public void testNoNPEOnNull() {
try {
AtomicBoolean errorDropped = new AtomicBoolean();
Hooks.onErrorDropped(t -> errorDropped.set(true));

Document doc = new Document("x", null);
Document doc2 = new Document("x", "hello");

Mono.from(collection.insertMany(Arrays.asList(doc, doc2))).block();

TestSubscriber<String> subscriber = new TestSubscriber<>();

collection.distinct("x", String.class).subscribe(subscriber);

subscriber.requestMore(1);

subscriber.assertReceivedOnNext(Arrays.asList("hello"));

assertFalse(errorDropped.get());
} finally {
Hooks.resetOnErrorDropped();
}
}

@Test
@DisplayName("Ensure BatchCursor reports cursor errors")
@SuppressWarnings("OptionalGetWithoutIsPresent")
Expand Down