deeplearning4j/deeplearning4j · error · IllegalStateException

Unknown array type (or not an array):

Error message

Unknown array type (or not an array): 

What it means

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.

Solutions

  1. Verify the input is a properly nested array with supported primitive-array leaves before calling.
  2. Convert leaves to a supported type (e.g. float[]) prior to dimension probing.
  3. Use ArrayUtil.length(Object) or NDArray shape APIs (INDArray.shape()) for non-primitive data.
  4. Catch IllegalStateException and log the offending class (included in the message) to fix the input.

Example fix

// before
Object[] nested = { java.util.Arrays.asList(1f, 2f) };
int len = ArrayUtil.probeDimension(nested, 0); // throws Unknown array type (or not an array)
// after
Object[] nested = { new float[]{1f, 2f} };
int len = ArrayUtil.probeDimension(nested, 0); // 2
Defensive patterns

Strategy: type-guard

Validate before calling

// Java
static boolean isNestedPrimitiveArrayTree(Object o) {
    if (o instanceof Object[]) {
        for (Object e : (Object[]) o) if (!isNestedPrimitiveArrayTree(e)) return false;
        return true;
    }
    return o != null && o.getClass().isArray() && !(o instanceof Object[]);
}

Type guard

static boolean isPrimitiveArray(Object o) { return o != null && o.getClass().isArray() && !o.getClass().getComponentType().equals(Object.class); }

Try / catch

try {
    int len = ArrayUtil.probeDimension(nested, dim);
} catch (IllegalStateException e) {
    // message contains offending class; fix input or use custom walker
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/1f8cbf24d7bb1c98. Report an issue: GitHub.

Appendix: source

Thrown at nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java:4633

            return ((Object[]) current).length;
        } else if (current instanceof double[]) {
            return ((double[]) current).length;
        } else if (current instanceof float[]) {
            return ((float[]) current).length;
        } else if (current instanceof long[]) {
            return ((long[]) current).length;
        } else if (current instanceof int[]) {
            return ((int[]) current).length;
        } else if (current instanceof byte[]) {
            return ((byte[]) current).length;
        } else if (current instanceof char[]) {
            return ((char[]) current).length;
        } else if (current instanceof boolean[]) {
            return ((boolean[]) current).length;
        } else if (current instanceof short[]) {
            return ((short[]) current).length;
        } else
            throw new IllegalStateException("Unknown array type (or not an array): " + current.getClass()); //Should never happen
    }

    /**
     * Compute the inverse permutation indices for a permutation operation<br>
     * Example: if input is [2, 0, 1] then output is [1, 2, 0]<br>
     * The idea is that x.permute(input).permute(invertPermutation(input)) == x
     *
     * @param input 1D indices for permutation
     * @return 1D inverted permutation
     */
    public static int[] invertPermutation(int... input){
        int[] target = new int[input.length];

        for(int i = 0 ; i < input.length ; i++){
            target[input[i]] = i;
        }

        return target;

View on GitHub (pinned to 4c22ac5fe4)