Skip to content

Commit e6bf508

Browse files
committed
JAVA-3057 Allow decoding a UDT that has more fields than expected
1 parent 741df6f commit e6bf508

File tree

2 files changed

+13
-16
lines changed
  • core/src

2 files changed

+13
-16
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/UdtCodec.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ public UdtValue decode(@Nullable ByteBuffer bytes, @NonNull ProtocolVersion prot
105105
int i = 0;
106106
while (input.hasRemaining()) {
107107
if (i == cqlType.getFieldTypes().size()) {
108-
throw new IllegalArgumentException(
109-
String.format(
110-
"Too many fields in encoded UDT value, expected %d",
111-
cqlType.getFieldTypes().size()));
108+
break;
112109
}
113110
int elementSize = input.getInt();
114111
ByteBuffer element;

core/src/test/java/com/datastax/oss/driver/internal/core/type/codec/UdtCodecTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,18 @@ public void should_decode_udt() {
134134
}
135135

136136
@Test
137-
public void should_fail_to_decode_udt_when_too_many_fields() {
138-
assertThatThrownBy(
139-
() ->
140-
decode(
141-
"0x"
142-
+ ("00000004" + "00000001")
143-
+ "ffffffff"
144-
+ ("00000001" + "61")
145-
// extra contents
146-
+ "ffffffff"))
147-
.isInstanceOf(IllegalArgumentException.class)
148-
.hasMessage("Too many fields in encoded UDT value, expected 3");
137+
public void should_decode_udt_when_too_many_fields() {
138+
UdtValue udt =
139+
decode(
140+
"0x"
141+
+ ("00000004" + "00000001")
142+
+ "ffffffff"
143+
+ ("00000001" + "61")
144+
// extra contents
145+
+ "ffffffff");
146+
assertThat(udt.getInt(0)).isEqualTo(1);
147+
assertThat(udt.isNull(1)).isTrue();
148+
assertThat(udt.getString(2)).isEqualTo("a");
149149
}
150150

151151
/** Test for JAVA-2557. Ensures that the codec can decode null fields with any negative length. */

0 commit comments

Comments
 (0)