You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/06/06 05:26:07 UTC

[GitHub] [pulsar] shink commented on a diff in pull request #15939: [SpotBugs][pulsar-io] Enable spotbugs for pulsar-io-mongo

shink commented on code in PR #15939:
URL: https://github.com/apache/pulsar/pull/15939#discussion_r889832030


##########
pulsar-io/mongo/src/main/java/org/apache/pulsar/io/mongodb/MongoSource.java:
##########
@@ -133,9 +134,12 @@ public void onNext(ChangeStreamDocument<Document> doc) {
                     recordValue.put("ns", doc.getNamespace());
                     recordValue.put("operation", doc.getOperationType());
 
-                    consume(new DocRecord(
-                            Optional.of(doc.getDocumentKey().toJson()),
-                            mapper.writeValueAsString(recordValue).getBytes(StandardCharsets.UTF_8)));
+                    BsonDocument key = doc.getDocumentKey();
+                    if (key != null) {
+                        consume(new DocRecord(
+                                Optional.of(key.toJson()),
+                                mapper.writeValueAsString(recordValue).getBytes(StandardCharsets.UTF_8)));
+                    }

Review Comment:
   Should an exception be thrown if `doc.getDocumentKey()` returns null?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org