@SuppressWarnings("unchecked")
    @Nullable
    @Override
    public T getValue(ResultSet rs, int startIndex) throws SQLException {
        Array arr = rs.getArray(startIndex);
        if (arr != null) {
            /*
             * The Javadoc for getArray() is annoyingly ambiguous about what it returns.
             * 
             * It says that the method can return a primitive array.
             * 
             * But it does not say anything about the type of the array when the method
             * returns an array of objects.
             * 
             * In that case, it could return T[] (Postgres appears to do this)
             * or it could return Object[] (H2 and HSQLDB appear to do this).
             * 
             * The JDBC specification does not offer any additional clarity.
             * 
             * In any case, what we need to return is T[]. Otherwise the caller will get
             * ClassCastExceptions at runtime.
             * 
             * Note that we cannot cast arr.getArray() to Object[] because, if the returned
             * array is a primitive array, that would cause ClassCastException.
             */
            Object rv = arr.getArray();
            if (!type.isAssignableFrom(rv.getClass())) {
                int length = java.lang.reflect.Array.getLength(rv);
                Object rv2 = java.lang.reflect.Array.newInstance(type.getComponentType(), length);
                copy(rv, rv2, length);
                return (T) rv2;
            } else {
                return (T) rv;
            }
        } else {
            return null;
        }
    }
{@code ArrayType} maps Java arrays to JDBC arrays

@param <T>
querydsl-sql/src/main/java/com/querydsl/sql/types/ArrayType.java