{"record":{"id":"1f8cbf24d7bb1c98","repo":"deeplearning4j/deeplearning4j","slug":"unknown-array-type-or-not-an-array","errorCode":null,"errorMessage":"Unknown array type (or not an array): ","messagePattern":"Unknown array type \\(or not an array\\): ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java","lineNumber":4633,"sourceCode":"            return ((Object[]) current).length;\n        } else if (current instanceof double[]) {\n            return ((double[]) current).length;\n        } else if (current instanceof float[]) {\n            return ((float[]) current).length;\n        } else if (current instanceof long[]) {\n            return ((long[]) current).length;\n        } else if (current instanceof int[]) {\n            return ((int[]) current).length;\n        } else if (current instanceof byte[]) {\n            return ((byte[]) current).length;\n        } else if (current instanceof char[]) {\n            return ((char[]) current).length;\n        } else if (current instanceof boolean[]) {\n            return ((boolean[]) current).length;\n        } else if (current instanceof short[]) {\n            return ((short[]) current).length;\n        } else\n            throw new IllegalStateException(\"Unknown array type (or not an array): \" + current.getClass()); //Should never happen\n    }\n\n    /**\n     * Compute the inverse permutation indices for a permutation operation<br>\n     * Example: if input is [2, 0, 1] then output is [1, 2, 0]<br>\n     * The idea is that x.permute(input).permute(invertPermutation(input)) == x\n     *\n     * @param input 1D indices for permutation\n     * @return 1D inverted permutation\n     */\n    public static int[] invertPermutation(int... input){\n        int[] target = new int[input.length];\n\n        for(int i = 0 ; i < input.length ; i++){\n            target[input[i]] = i;\n        }\n\n        return target;","sourceCodeStart":4615,"sourceCodeEnd":4651,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java#L4615-L4651","documentation":"ArrayUtil's dimension/length probe walks nested arrays and, at the deepest level, matches the element against supported primitive array types to return its length. When the leaf is not a recognized array type, it throws IllegalStateException including the offending object's class, since it cannot determine a dimension length. Like error 4263, it is an internal type-dispatch guard exposed by malformed input.","triggerScenarios":"Calling a dimension/length helper such as ArrayUtil.probeDimension(...) on an Object[] tree whose leaf element is a String, boxed number, POJO, or a primitive-array type not covered by the instanceof chain.","commonSituations":"Inspecting shapes of heterogeneous or deserialized object graphs; accidentally passing a single scalar or Collection instead of nested arrays; using byte[]/Object leaf data parsed from external sources.","solutions":["Verify the input is a properly nested array with supported primitive-array leaves before calling.","Convert leaves to a supported type (e.g. float[]) prior to dimension probing.","Use ArrayUtil.length(Object) or NDArray shape APIs (INDArray.shape()) for non-primitive data.","Catch IllegalStateException and log the offending class (included in the message) to fix the input."],"exampleFix":"// before\nObject[] nested = { java.util.Arrays.asList(1f, 2f) };\nint len = ArrayUtil.probeDimension(nested, 0); // throws Unknown array type (or not an array)\n// after\nObject[] nested = { new float[]{1f, 2f} };\nint len = ArrayUtil.probeDimension(nested, 0); // 2","handlingStrategy":"type-guard","validationCode":"// Java\nstatic boolean isNestedPrimitiveArrayTree(Object o) {\n    if (o instanceof Object[]) {\n        for (Object e : (Object[]) o) if (!isNestedPrimitiveArrayTree(e)) return false;\n        return true;\n    }\n    return o != null && o.getClass().isArray() && !(o instanceof Object[]);\n}","typeGuard":"static boolean isPrimitiveArray(Object o) { return o != null && o.getClass().isArray() && !o.getClass().getComponentType().equals(Object.class); }","tryCatchPattern":"try {\n    int len = ArrayUtil.probeDimension(nested, dim);\n} catch (IllegalStateException e) {\n    // message contains offending class; fix input or use custom walker\n}","preventionTips":["Verify input is truly nested arrays, not Collections or scalars","Convert Lists to arrays before dimension probing","Use ArrayUtil.length(Object) for generic objects","Log the class name from the message to trace malformed data sources"],"tags":["java","nd4j","unsupported-type","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}