You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "absurdfarce (via GitHub)" <gi...@apache.org> on 2024/02/02 22:19:54 UTC

Re: [PR] Fix decode in VectorCodec [cassandra-java-driver]

absurdfarce commented on code in PR #1909:
URL: https://github.com/apache/cassandra-java-driver/pull/1909#discussion_r1476798500


##########
core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java:
##########
@@ -127,17 +127,19 @@ Elements should at least precede themselves with their size (along the lines of
               cqlType.getDimensions(), bytes.remaining()));
     }
 
+    ByteBuffer slice = bytes.slice();
     List<SubtypeT> rv = new ArrayList<SubtypeT>(cqlType.getDimensions());
     for (int i = 0; i < cqlType.getDimensions(); ++i) {
-      ByteBuffer slice = bytes.slice();
-      slice.limit(elementSize);
+      // Set the limit for the current element
+      int originalPosition = slice.position();
+      slice.limit(originalPosition + elementSize);
       rv.add(this.subtypeCodec.decode(slice, protocolVersion));
-      bytes.position(bytes.position() + elementSize);
+      // Move to the start of the next element
+      slice.position(originalPosition + elementSize);

Review Comment:
   Just an observation: this would cause us to miss elements (possibly silently) for subtypes which have a codec that consumes the input ByteBuffer.  I'm pretty sure this isn't the only composite/collection codec that that's true for, however, and any such subtype codec would have to ignore the [explicit guidance](https://docs.datastax.com/en/drivers/java/4.17/com/datastax/oss/driver/api/core/type/codec/TypeCodec.html) on TypeCodec Javadoc anyways... so we're already in a misbehaving world in that 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: commits-unsubscribe@cassandra.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org