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:55:25 UTC

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

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


##########
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:
   @shink I think we don't need to throw exception. We also can
   ```java
   Optional.ofNullable(doc.getDocumentKey()).map(BsonDocument::toJson),
   ```



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