SiyaoIsHiding commented on code in PR #2060:
URL: 
https://github.com/apache/cassandra-java-driver/pull/2060#discussion_r2492550851


##########
core/src/main/java/com/datastax/oss/driver/api/core/tracker/RequestIdGenerator.java:
##########
@@ -67,11 +67,27 @@ default String getCustomPayloadKey() {
 
   default Statement<?> getDecoratedStatement(
       @NonNull Statement<?> statement, @NonNull String requestId) {
-    Map<String, ByteBuffer> customPayload =
-        NullAllowingImmutableMap.<String, ByteBuffer>builder()
-            .putAll(statement.getCustomPayload())
-            .put(getCustomPayloadKey(), 
ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8)))
-            .build();
-    return statement.setCustomPayload(customPayload);
+
+    // local copy
+    Map<String, ByteBuffer> existing = statement.getCustomPayload();
+    String key = getCustomPayloadKey();
+
+    NullAllowingImmutableMap.Builder<String, ByteBuffer> builder =

Review Comment:
   re: what map to use.
   
   It seems like the protocol allows null values in the custom payload 
([source](https://docs.datastax.com/en/developer/java-driver/3.6/manual/custom_payloads/index.html)).
 
   
   So the custom payload provided by the user can already have null values in 
it, and we need to support that.
   
   But a normal `ImmutableMap` does not allow a null value. I'm guessing that's 
why we were using a `NullAllowingImmutableMap`. Pending for @olim7t and 
@emerkle826 to confirm.
   
   However, `Collections.unmodifiableMap` is also immutable and allows null 
values. I cannot quite see why we don't use that.
   
   The code here will be cleaner if we use `Collections.unmodifiableMap`. If no 
objections, I think we can go that way.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to