Skip to content

Commit 055a29a

Browse files
detinhoolim7t
authored andcommitted
JAVA-1767: Improve message when column not in result set
1 parent 47643a0 commit 055a29a

12 files changed

Lines changed: 175 additions & 126 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.0.0-alpha4 (in progress)
66

7+
- [improvement] JAVA-1767: Improve message when column not in result set
78
- [improvement] JAVA-1624: Expose ExecutionInfo on exceptions where applicable
89
- [improvement] JAVA-1766: Revisit nullability
910
- [new feature] JAVA-1860: Allow reconnection at startup if no contact point is available

core/src/main/java/com/datastax/oss/driver/api/core/cql/BoundStatementBuilder.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ public BoundStatementBuilder(@NonNull BoundStatement template) {
6262

6363
@Override
6464
public int firstIndexOf(@NonNull CqlIdentifier id) {
65-
return variableDefinitions.firstIndexOf(id);
65+
int indexOf = variableDefinitions.firstIndexOf(id);
66+
if (indexOf == -1) {
67+
throw new IllegalArgumentException(id + " is not a variable in this bound statement");
68+
}
69+
return indexOf;
6670
}
6771

6872
@Override
6973
public int firstIndexOf(@NonNull String name) {
70-
return variableDefinitions.firstIndexOf(name);
74+
int indexOf = variableDefinitions.firstIndexOf(name);
75+
if (indexOf == -1) {
76+
throw new IllegalArgumentException(name + " is not a variable in this bound statement");
77+
}
78+
return indexOf;
7179
}
7280

7381
@NonNull

core/src/main/java/com/datastax/oss/driver/api/core/data/AccessibleById.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public interface AccessibleById extends AccessibleByIndex {
2929
/**
3030
* Returns the first index where a given identifier appears (depending on the implementation,
3131
* identifiers may appear multiple times).
32+
*
33+
* @throws IllegalArgumentException if the id is invalid.
3234
*/
3335
int firstIndexOf(@NonNull CqlIdentifier id);
3436

@@ -38,7 +40,7 @@ public interface AccessibleById extends AccessibleByIndex {
3840
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
3941
* this method that takes a string argument.
4042
*
41-
* @throws IndexOutOfBoundsException if the index is invalid.
43+
* @throws IllegalArgumentException if the id is invalid.
4244
*/
4345
@NonNull
4446
DataType getType(@NonNull CqlIdentifier id);

core/src/main/java/com/datastax/oss/driver/api/core/data/AccessibleByName.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public interface AccessibleByName extends AccessibleByIndex {
4545
/**
4646
* Returns the first index where a given identifier appears (depending on the implementation,
4747
* identifiers may appear multiple times).
48+
*
49+
* @throws IllegalArgumentException if the name is invalid.
4850
*/
4951
int firstIndexOf(@NonNull String name);
5052

@@ -54,7 +56,7 @@ public interface AccessibleByName extends AccessibleByIndex {
5456
* <p>This method deals with case sensitivity in the way explained in the documentation of {@link
5557
* GettableByName}.
5658
*
57-
* @throws IndexOutOfBoundsException if the index is invalid.
59+
* @throws IllegalArgumentException if the name is invalid.
5860
*/
5961
@NonNull
6062
DataType getType(@NonNull String name);

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableById.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public interface GettableById extends GettableByIndex, AccessibleById {
5454
* make sure to {@link ByteBuffer#duplicate() duplicate} it beforehand, or only use relative
5555
* methods. If you change the buffer's index or its contents in any way, any other getter
5656
* invocation for this value will have unpredictable results.
57-
* @throws IndexOutOfBoundsException if the id is invalid.
57+
* @throws IllegalArgumentException if the id is invalid.
5858
*/
5959
@Nullable
6060
default ByteBuffer getBytesUnsafe(@NonNull CqlIdentifier id) {
@@ -70,7 +70,7 @@ default ByteBuffer getBytesUnsafe(@NonNull CqlIdentifier id) {
7070
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
7171
* this method that takes a string argument.
7272
*
73-
* @throws IndexOutOfBoundsException if the id is invalid.
73+
* @throws IllegalArgumentException if the id is invalid.
7474
*/
7575
default boolean isNull(@NonNull CqlIdentifier id) {
7676
return isNull(firstIndexOf(id));
@@ -93,7 +93,7 @@ default boolean isNull(@NonNull CqlIdentifier id) {
9393
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
9494
* this method that takes a string argument.
9595
*
96-
* @throws IndexOutOfBoundsException if the id is invalid.
96+
* @throws IllegalArgumentException if the id is invalid.
9797
*/
9898
@Nullable
9999
default <T> T get(@NonNull CqlIdentifier id, @NonNull TypeCodec<T> codec) {
@@ -114,7 +114,7 @@ default <T> T get(@NonNull CqlIdentifier id, @NonNull TypeCodec<T> codec) {
114114
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
115115
* this method that takes a string argument.
116116
*
117-
* @throws IndexOutOfBoundsException if the id is invalid.
117+
* @throws IllegalArgumentException if the id is invalid.
118118
* @throws CodecNotFoundException if no codec can perform the conversion.
119119
*/
120120
@Nullable
@@ -135,7 +135,7 @@ default <T> T get(@NonNull CqlIdentifier id, @NonNull GenericType<T> targetType)
135135
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
136136
* this method that takes a string argument.
137137
*
138-
* @throws IndexOutOfBoundsException if the id is invalid.
138+
* @throws IllegalArgumentException if the id is invalid.
139139
* @throws CodecNotFoundException if no codec can perform the conversion.
140140
*/
141141
@Nullable
@@ -166,7 +166,7 @@ default <T> T get(@NonNull CqlIdentifier id, @NonNull Class<T> targetClass) {
166166
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
167167
* this method that takes a string argument.
168168
*
169-
* @throws IndexOutOfBoundsException if the id is invalid.
169+
* @throws IllegalArgumentException if the id is invalid.
170170
* @throws CodecNotFoundException if no codec can perform the conversion.
171171
*/
172172
@Nullable
@@ -190,7 +190,7 @@ default Object getObject(@NonNull CqlIdentifier id) {
190190
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
191191
* this method that takes a string argument.
192192
*
193-
* @throws IndexOutOfBoundsException if the id is invalid.
193+
* @throws IllegalArgumentException if the id is invalid.
194194
*/
195195
default boolean getBoolean(@NonNull CqlIdentifier id) {
196196
return getBoolean(firstIndexOf(id));
@@ -211,7 +211,7 @@ default boolean getBoolean(@NonNull CqlIdentifier id) {
211211
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
212212
* this method that takes a string argument.
213213
*
214-
* @throws IndexOutOfBoundsException if the id is invalid.
214+
* @throws IllegalArgumentException if the id is invalid.
215215
*/
216216
default byte getByte(@NonNull CqlIdentifier id) {
217217
return getByte(firstIndexOf(id));
@@ -233,7 +233,7 @@ default byte getByte(@NonNull CqlIdentifier id) {
233233
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
234234
* this method that takes a string argument.
235235
*
236-
* @throws IndexOutOfBoundsException if the id is invalid.
236+
* @throws IllegalArgumentException if the id is invalid.
237237
*/
238238
default double getDouble(@NonNull CqlIdentifier id) {
239239
return getDouble(firstIndexOf(id));
@@ -255,7 +255,7 @@ default double getDouble(@NonNull CqlIdentifier id) {
255255
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
256256
* this method that takes a string argument.
257257
*
258-
* @throws IndexOutOfBoundsException if the id is invalid.
258+
* @throws IllegalArgumentException if the id is invalid.
259259
*/
260260
default float getFloat(@NonNull CqlIdentifier id) {
261261
return getFloat(firstIndexOf(id));
@@ -277,7 +277,7 @@ default float getFloat(@NonNull CqlIdentifier id) {
277277
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
278278
* this method that takes a string argument.
279279
*
280-
* @throws IndexOutOfBoundsException if the id is invalid.
280+
* @throws IllegalArgumentException if the id is invalid.
281281
*/
282282
default int getInt(@NonNull CqlIdentifier id) {
283283
return getInt(firstIndexOf(id));
@@ -298,7 +298,7 @@ default int getInt(@NonNull CqlIdentifier id) {
298298
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
299299
* this method that takes a string argument.
300300
*
301-
* @throws IndexOutOfBoundsException if the id is invalid.
301+
* @throws IllegalArgumentException if the id is invalid.
302302
*/
303303
default long getLong(@NonNull CqlIdentifier id) {
304304
return getLong(firstIndexOf(id));
@@ -320,7 +320,7 @@ default long getLong(@NonNull CqlIdentifier id) {
320320
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
321321
* this method that takes a string argument.
322322
*
323-
* @throws IndexOutOfBoundsException if the id is invalid.
323+
* @throws IllegalArgumentException if the id is invalid.
324324
*/
325325
default short getShort(@NonNull CqlIdentifier id) {
326326
return getShort(firstIndexOf(id));
@@ -337,7 +337,7 @@ default short getShort(@NonNull CqlIdentifier id) {
337337
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
338338
* this method that takes a string argument.
339339
*
340-
* @throws IndexOutOfBoundsException if the id is invalid.
340+
* @throws IllegalArgumentException if the id is invalid.
341341
*/
342342
@Nullable
343343
default Instant getInstant(@NonNull CqlIdentifier id) {
@@ -355,7 +355,7 @@ default Instant getInstant(@NonNull CqlIdentifier id) {
355355
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
356356
* this method that takes a string argument.
357357
*
358-
* @throws IndexOutOfBoundsException if the id is invalid.
358+
* @throws IllegalArgumentException if the id is invalid.
359359
*/
360360
@Nullable
361361
default LocalDate getLocalDate(@NonNull CqlIdentifier id) {
@@ -373,7 +373,7 @@ default LocalDate getLocalDate(@NonNull CqlIdentifier id) {
373373
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
374374
* this method that takes a string argument.
375375
*
376-
* @throws IndexOutOfBoundsException if the id is invalid.
376+
* @throws IllegalArgumentException if the id is invalid.
377377
*/
378378
@Nullable
379379
default LocalTime getLocalTime(@NonNull CqlIdentifier id) {
@@ -391,7 +391,7 @@ default LocalTime getLocalTime(@NonNull CqlIdentifier id) {
391391
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
392392
* this method that takes a string argument.
393393
*
394-
* @throws IndexOutOfBoundsException if the id is invalid.
394+
* @throws IllegalArgumentException if the id is invalid.
395395
*/
396396
@Nullable
397397
default ByteBuffer getByteBuffer(@NonNull CqlIdentifier id) {
@@ -409,7 +409,7 @@ default ByteBuffer getByteBuffer(@NonNull CqlIdentifier id) {
409409
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
410410
* this method that takes a string argument.
411411
*
412-
* @throws IndexOutOfBoundsException if the id is invalid.
412+
* @throws IllegalArgumentException if the id is invalid.
413413
*/
414414
@Nullable
415415
default String getString(@NonNull CqlIdentifier id) {
@@ -427,7 +427,7 @@ default String getString(@NonNull CqlIdentifier id) {
427427
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
428428
* this method that takes a string argument.
429429
*
430-
* @throws IndexOutOfBoundsException if the id is invalid.
430+
* @throws IllegalArgumentException if the id is invalid.
431431
*/
432432
@Nullable
433433
default BigInteger getBigInteger(@NonNull CqlIdentifier id) {
@@ -445,7 +445,7 @@ default BigInteger getBigInteger(@NonNull CqlIdentifier id) {
445445
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
446446
* this method that takes a string argument.
447447
*
448-
* @throws IndexOutOfBoundsException if the id is invalid.
448+
* @throws IllegalArgumentException if the id is invalid.
449449
*/
450450
@Nullable
451451
default BigDecimal getBigDecimal(@NonNull CqlIdentifier id) {
@@ -463,7 +463,7 @@ default BigDecimal getBigDecimal(@NonNull CqlIdentifier id) {
463463
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
464464
* this method that takes a string argument.
465465
*
466-
* @throws IndexOutOfBoundsException if the id is invalid.
466+
* @throws IllegalArgumentException if the id is invalid.
467467
*/
468468
@Nullable
469469
default UUID getUuid(@NonNull CqlIdentifier id) {
@@ -481,7 +481,7 @@ default UUID getUuid(@NonNull CqlIdentifier id) {
481481
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
482482
* this method that takes a string argument.
483483
*
484-
* @throws IndexOutOfBoundsException if the id is invalid.
484+
* @throws IllegalArgumentException if the id is invalid.
485485
*/
486486
@Nullable
487487
default InetAddress getInetAddress(@NonNull CqlIdentifier id) {
@@ -499,7 +499,7 @@ default InetAddress getInetAddress(@NonNull CqlIdentifier id) {
499499
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
500500
* this method that takes a string argument.
501501
*
502-
* @throws IndexOutOfBoundsException if the id is invalid.
502+
* @throws IllegalArgumentException if the id is invalid.
503503
*/
504504
@Nullable
505505
default CqlDuration getCqlDuration(@NonNull CqlIdentifier id) {
@@ -522,8 +522,8 @@ default CqlDuration getCqlDuration(@NonNull CqlIdentifier id) {
522522
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
523523
* this method that takes a string argument.
524524
*
525-
* @throws IndexOutOfBoundsException if the index is invalid.
526-
* @throws IllegalArgumentException if the column type can not be converted to a known token type.
525+
* @throws IllegalArgumentException if the column type can not be converted to a known token type
526+
* or if the name is invalid.
527527
*/
528528
@Nullable
529529
default Token getToken(@NonNull CqlIdentifier id) {
@@ -548,7 +548,7 @@ default Token getToken(@NonNull CqlIdentifier id) {
548548
* Whether this method will return an empty collection or {@code null} will depend on the codec
549549
* used; by default, the driver's built-in codecs all return empty collections.
550550
*
551-
* @throws IndexOutOfBoundsException if the id is invalid.
551+
* @throws IllegalArgumentException if the id is invalid.
552552
*/
553553
@Nullable
554554
default <T> List<T> getList(@NonNull CqlIdentifier id, @NonNull Class<T> elementsClass) {
@@ -573,7 +573,7 @@ default <T> List<T> getList(@NonNull CqlIdentifier id, @NonNull Class<T> element
573573
* Whether this method will return an empty collection or {@code null} will depend on the codec
574574
* used; by default, the driver's built-in codecs all return empty collections.
575575
*
576-
* @throws IndexOutOfBoundsException if the id is invalid.
576+
* @throws IllegalArgumentException if the id is invalid.
577577
*/
578578
@Nullable
579579
default <T> Set<T> getSet(@NonNull CqlIdentifier id, @NonNull Class<T> elementsClass) {
@@ -598,7 +598,7 @@ default <T> Set<T> getSet(@NonNull CqlIdentifier id, @NonNull Class<T> elementsC
598598
* Whether this method will return an empty collection or {@code null} will depend on the codec
599599
* used; by default, the driver's built-in codecs all return empty collections.
600600
*
601-
* @throws IndexOutOfBoundsException if the id is invalid.
601+
* @throws IllegalArgumentException if the id is invalid.
602602
*/
603603
@Nullable
604604
default <K, V> Map<K, V> getMap(
@@ -617,7 +617,7 @@ default <K, V> Map<K, V> getMap(
617617
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
618618
* this method that takes a string argument.
619619
*
620-
* @throws IndexOutOfBoundsException if the id is invalid.
620+
* @throws IllegalArgumentException if the id is invalid.
621621
*/
622622
@Nullable
623623
default UdtValue getUdtValue(@NonNull CqlIdentifier id) {
@@ -635,7 +635,7 @@ default UdtValue getUdtValue(@NonNull CqlIdentifier id) {
635635
* <p>If you want to avoid the overhead of building a {@code CqlIdentifier}, use the variant of
636636
* this method that takes a string argument.
637637
*
638-
* @throws IndexOutOfBoundsException if the id is invalid.
638+
* @throws IllegalArgumentException if the id is invalid.
639639
*/
640640
@Nullable
641641
default TupleValue getTupleValue(@NonNull CqlIdentifier id) {

0 commit comments

Comments
 (0)