Skip to content

Commit c07160d

Browse files
committed
Improve type casting in Tuple#get and Tuple#getValues
1 parent bd0f74d commit c07160d

File tree

1 file changed

+5
-16
lines changed
  • vertx-sql-client/src/main/java/io/vertx/sqlclient

1 file changed

+5
-16
lines changed

vertx-sql-client/src/main/java/io/vertx/sqlclient/Tuple.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,20 +1388,10 @@ default <T> T get(Class<T> type, int pos) {
13881388
throw new IllegalArgumentException("Accessor type can not be null");
13891389
}
13901390
Object value = getValue(pos);
1391-
if (value.getClass() == type) {
1391+
if (value != null && type.isAssignableFrom(value.getClass())) {
13921392
return type.cast(value);
1393-
} else {
1394-
try {
1395-
if (value instanceof Buffer) {
1396-
return type.cast(value);
1397-
} else if (value instanceof Temporal) {
1398-
return type.cast(value);
1399-
}
1400-
} catch (ClassCastException e) {
1401-
throw new IllegalArgumentException("mismatched type [" + type.getName() + "] for the value of type [" + value.getClass().getName() + "]");
1402-
}
1403-
throw new IllegalArgumentException("mismatched type [" + type.getName() + "] for the value of type [" + value.getClass().getName() + "]");
14041393
}
1394+
return null;
14051395
}
14061396

14071397
@GenIgnore
@@ -1410,11 +1400,10 @@ default <T> T[] getValues(Class<T> type, int pos) {
14101400
throw new IllegalArgumentException("Accessor type can not be null");
14111401
}
14121402
Object value = getValue(pos);
1413-
if (value.getClass().isArray() && value.getClass().getComponentType() == type) {
1403+
if (value != null && value.getClass().isArray() && type.isAssignableFrom(value.getClass().getComponentType())) {
14141404
return (T[]) value;
1415-
} else {
1416-
throw new IllegalArgumentException("mismatched array element type [" + type.getName() + "] for the value of type [" + value.getClass().getName() + "]");
14171405
}
1406+
return null;
14181407
}
14191408

14201409
@GenIgnore
@@ -1428,7 +1417,7 @@ default <T> Tuple addValues(T[] value) {
14281417
int size();
14291418

14301419
void clear();
1431-
1420+
14321421
/**
14331422
* @return A String containing the {@link Object#toString} value of each element,
14341423
* separated by a comma (,) character

0 commit comments

Comments
 (0)