{"record":{"id":"72704ea5f005c3a5","repo":"deeplearning4j/deeplearning4j","slug":"unknown-array-type","errorCode":null,"errorMessage":"Unknown array type","messagePattern":"Unknown array type","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java","lineNumber":3980,"sourceCode":"            shape[shape.length - 1] = ((Object[]) current).length;\n        } else if (current instanceof double[]) {\n            shape[shape.length - 1] = ((double[]) current).length;\n        } else if (current instanceof float[]) {\n            shape[shape.length - 1] = ((float[]) current).length;\n        } else if (current instanceof long[]) {\n            shape[shape.length - 1] = ((long[]) current).length;\n        } else if (current instanceof int[]) {\n            shape[shape.length - 1] = ((int[]) current).length;\n        } else if (current instanceof byte[]) {\n            shape[shape.length - 1] = ((byte[]) current).length;\n        } else if (current instanceof char[]) {\n            shape[shape.length - 1] = ((char[]) current).length;\n        } else if (current instanceof boolean[]) {\n            shape[shape.length - 1] = ((boolean[]) current).length;\n        } else if (current instanceof short[]) {\n            shape[shape.length - 1] = ((short[]) current).length;\n        } else\n            throw new IllegalStateException(\"Unknown array type\"); //Should never happen\n        return shape;\n    }\n\n\n    /** Returns the maximum value in the array */\n    public static int max(int[] in) {\n        int max = Integer.MIN_VALUE;\n        for (int i = 0; i < in.length; i++)\n            if (in[i] > max)\n                max = in[i];\n        return max;\n    }\n\n    /** Returns the minimum value in the array */\n    public static int min(int[] in) {\n        int min = Integer.MAX_VALUE;\n        for (int i = 0; i < in.length; i++)\n            if (in[i] < min)","sourceCodeStart":3962,"sourceCodeEnd":3998,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java#L3962-L3998","documentation":"At the deepest level of arrayShape(), the code dispatches on the runtime type of the innermost element to read its length; it recognizes float[], int[], double[], long[], char[], boolean[] and short[]. If the element is any other type (a non-array object, a String, Integer, boxed value, or exotic primitive array like byte[] depending on the chain), no branch matches and an IllegalStateException('Unknown array type') is thrown. The comment notes it 'should never happen' for well-formed arrays of supported types.","triggerScenarios":"Calling ArrayUtil.arrayShape(...) on a nested Object[] whose leaf elements are not one of the supported primitive arrays - e.g. leaf is a String, boxed Float, byte[], or an arbitrary POJO.","commonSituations":"Deserialized or reflective data where leaves are boxed or byte[]; mixing object graphs (e.g. NDArray wrappers) into Object[] trees before shape inspection.","solutions":["Ensure leaves are primitive arrays of the supported types (float[], int[], double[], long[], char[], boolean[], short[]).","Convert unsupported leaves first, e.g. copy byte[] to int[] or unbox Float[] to float[], before computing shape.","Use ArrayUtil.length(Object)/dimensions-based helpers or write a custom shape walker for custom types.","Catch IllegalStateException and reject/log the malformed input."],"exampleFix":"// before\nObject[] nested = { new String[]{\"a\", \"b\"} };\nlong[] shape = ArrayUtil.arrayShape(nested); // throws Unknown array type\n// after\nObject[] nested = { new float[]{1f, 2f} };\nlong[] shape = ArrayUtil.arrayShape(nested); // [1, 2]","handlingStrategy":"type-guard","validationCode":"// Java\nstatic boolean hasSupportedLeaf(Object o) {\n    if (o instanceof Object[]) {\n        for (Object e : (Object[]) o) if (!hasSupportedLeaf(e)) return false;\n        return true;\n    }\n    return o instanceof float[] || o instanceof int[] || o instanceof double[]\n        || o instanceof long[] || o instanceof char[] || o instanceof boolean[] || o instanceof short[];\n}","typeGuard":"static boolean isSupportedPrimitiveArray(Object o) { return o instanceof float[] || o instanceof int[] || o instanceof double[] || o instanceof long[] || o instanceof char[] || o instanceof boolean[] || o instanceof short[]; }","tryCatchPattern":"try {\n    long[] shape = ArrayUtil.arrayShape(nested);\n} catch (IllegalStateException e) {\n    // leaf type unsupported; convert or use custom shape logic\n}","preventionTips":["Only build nested arrays from supported primitive-array leaves","Convert byte[]/boxed data to supported arrays before shape inspection","Prefer INDArray.shape() for tensor data instead of Object[] trees","Unit-test shape helpers with the exact data types your loader produces"],"tags":["java","nd4j","unsupported-type","shape-calculation"],"backgroundTag":"unsupported-dtype","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"}