public static Object[] toArray(Object arrayObj) {
        if (arrayObj == null) {
            return null;
        }

        if (!arrayObj.getClass().isArray()) {
            throw new ClassCastException("'arrayObj' is not an array, can't cast to Object[]");
        }

        int length = Array.getLength(arrayObj);
        Object[] array = new Object[length];
        if (length > 0) {
            for (int i = 0; i < length; ++i) {
                array[i] = Array.get(arrayObj, i);
            }
        }
        return array;
    }
@Test
    public void testToArrayException() {
        Assertions.assertThrows(ClassCastException.class, () -> {
            Object[] array = ArrayUtils.toArray(new Object());
        });
    }