zhisheng17/flink-learning · error · IllegalArgumentException
The given argument is no array.
Error message
The given argument is no array.
What it means
StringUtils.arrayToString renders an array (primitive or object) as a string. After trying all known array component types it falls back: if the object is not an array at all, it throws IllegalArgumentException('The given argument is no array.').
Source
Thrown at flink-learning-core/src/main/java/com/zhisheng/core/utils/StringUtils.java:166
return Arrays.toString((double[]) array);
}
if (array instanceof float[]) {
return Arrays.toString((float[]) array);
}
if (array instanceof boolean[]) {
return Arrays.toString((boolean[]) array);
}
if (array instanceof char[]) {
return Arrays.toString((char[]) array);
}
if (array instanceof short[]) {
return Arrays.toString((short[]) array);
}
if (array.getClass().isArray()) {
return "<unknown array type>";
} else {
throw new IllegalArgumentException("The given argument is no array.");
}
}
/**
* Replaces control characters by their escape-coded version. For example,
* if the string contains a line break character ('\n'), this character will
* be replaced by the two characters backslash '\' and 'n'. As a consequence, the
* resulting string will not contain any more control characters.
*
* @param str The string in which to replace the control characters.
* @return The string with the replaced characters.
*/
public static String showControlCharacters(String str) {
int len = str.length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i += 1) {
char c = str.charAt(i);View on GitHub (pinned to d731cee761)
Solutions
- Pass an actual array (e.g. Object[], int[]) to arrayToString
- Convert collections first: list.toArray()
- Use arrayAwareToString which handles non-array objects by falling back to String.valueOf
Example fix
// before StringUtils.arrayToString(myList); // after StringUtils.arrayAwareToString(myList); // or myList.toArray()
Defensive patterns
Strategy: type-guard
Validate before calling
if (obj == null || !obj.getClass().isArray()) {
throw new IllegalArgumentException("arrayToString requires an array, got: " + (obj == null ? "null" : obj.getClass().getSimpleName()));
} Type guard
static boolean isArray(Object o) {
return o != null && o.getClass().isArray();
} Try / catch
try {
String s = StringUtils.arrayToString(arg);
} catch (IllegalArgumentException e) {
if ("The given argument is no array.".equals(e.getMessage())) {
s = String.valueOf(arg);
} else throw e;
} Prevention
- Use arrayAwareToString when the input type is unknown — it handles non-arrays
- Convert Collections with toArray() before array formatting
- Check Class.isArray() before calling array*ToString utilities
When it happens
Trigger: Calling arrayToString (directly or via arrayAwareToString) with a non-array object such as a String, List, or Integer — the method requires Class.isArray() to be true.
Common situations: Passing a List or Collection expecting it to be formatted like an array, or after a refactor changed a parameter from T[] to List<T> while the call site still calls arrayToString.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- bytes == null
- No measurement defined
- text does not start with a number
- The value '${number}' cannot be re represented as 64bit numb
- kubernetes.cluster-id must not be blank.
AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06).
Data as JSON: /api/errors/6811d791fff8f2c8.
Report an issue: GitHub.