absurdfarce commented on code in PR #2060:
URL:
https://github.com/apache/cassandra-java-driver/pull/2060#discussion_r2511520832
##########
core/src/main/java/com/datastax/oss/driver/api/core/tracker/RequestIdGenerator.java:
##########
@@ -67,11 +68,15 @@ 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);
+
+ Map<String, ByteBuffer> existing = new
HashMap<>(statement.getCustomPayload());
+ String key = getCustomPayloadKey();
+
+ // Add or overwrite
+ existing.put(key,
ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8)));
+
+ Map<String, ByteBuffer> unmodifiableMap =
Collections.unmodifiableMap(existing);
+
+ return statement.setCustomPayload(unmodifiableMap);
Review Comment:
That's probably right @tolbertam but in the end I don't think it matters
much. As I mentioned in my earlier comment my _hope_ was that the Guava
ImmutableMap code would be easier to read and comprehend but the necessity to
map null values there makes the code more convoluted. You do get the advantage
of having immutability as part of the type system but that doesn't but you much
if you just stick the results in a Statement where custom payload is just a Map
anyway.
Given all of that I'm okay with the original impl. My _primary_ goal in
this exercise was just to better understand (and document) how null handling
even entered into play here. The driver docs you cited clearly indicated that
null handling is possible (and relevant) here but I wanted to completely
understand why that was the case.
--
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]