alibaba/spring-ai-alibaba · error · IllegalStateException

Cannot instantiate array type: {}

Error message

Cannot instantiate array type: {}

What it means

JacksonDeserializer failed to load the array Class while reconstructing a typed array during state deserialization. Class.forName threw ClassNotFoundException for the recorded array component/type name, so the deserializer cannot allocate the array via Array.newInstance. This indicates the serialized state references an array type not present on the classpath or recorded in an unexpected format.

Source

Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/serializer/plain_text/jackson/JacksonDeserializer.java:489

				}
				
				if (element == null && !componentType.isPrimitive()) {
					Array.set(typedArray, i, null);
					continue;
				}
				if (element != null && !componentType.isInstance(element)) {
					// Type mismatch, fall back to generic Object array
					ObjectMapper mapperNoTyping = objectMapper.copy();
					mapperNoTyping.setDefaultTyping(null);
					mapperNoTyping.deactivateDefaultTyping();
					return payload.traverse(mapperNoTyping).readValueAs(Object[].class);
				}
				Array.set(typedArray, i, element);
			}
			return typedArray;
		}
		catch (ClassNotFoundException ex) {
			throw new IllegalStateException("Cannot instantiate array type: " + className, ex);
		}
	}

	/**
	 * Reconstruct a primitive array that Jackson's WRAPPER_ARRAY default typing serialized
	 * with a scalar (non-array) payload. Notably {@code byte[]} is written as a base64
	 * string and {@code char[]} as a plain string. Delegating to Jackson preserves the
	 * exact array type so values such as Gemini {@code thoughtSignatures} ({@code List<byte[]>})
	 * survive a serialize/clone round-trip.
	 * @param className the serialized component type id (e.g. {@code [B} or {@code byte[]})
	 * @param payload the scalar payload node
	 * @param objectMapper the ObjectMapper to bind with
	 * @return the reconstructed array
	 * @throws IOException if binding fails
	 */
	private static Object instantiateScalarPayloadArray(String className, JsonNode payload, ObjectMapper objectMapper)
			throws IOException {
		try {

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Ensure the array element class exists on the classpath with the exact same fully-qualified name used at serialization time
  2. Check the className in the serialized payload; array names must be JVM format like '[Ljava.lang.String;' or 'String[]' style
  3. Re-serialize state with the current application version instead of reusing old checkpoints
  4. If custom classes changed packages, migrate/rewrite old persisted state or keep a compatibility class

Example fix

// before: state checkpoint references com.example.OldDto[] which no longer exists
// after: keep the class or add a compatibility alias
package com.example;
public class OldDto { /* legacy shape kept for checkpoint compat */ }
// or regenerate the checkpoint with the current model classes
Defensive patterns

Strategy: validation

Validate before calling

try { Class.forName(componentClassName); } catch (ClassNotFoundException e) { throw new IllegalStateException("Checkpoint references missing class: " + componentClassName, e); }

Type guard

boolean isArrayTypeLoadable(String name) {
    try { resolveArrayClassLike(name); return true; } catch (Throwable t) { return false; }
}

Try / catch

try { state = deserializer.load(input); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Cannot instantiate array type")) { /* rebuild from fresh checkpoint */ } else throw e; }

Prevention

When it happens

Trigger: deserializeArrayNode -> instantiateArray: the WRAPPER_ARRAY type id names an array type whose class cannot be loaded (e.g. custom class deleted/renamed, different classloader, or a type name format resolveArrayClass does not map).

Common situations: Loading checkpoints/saver files written by an older or different version of the app where the array element class was renamed or moved; running deserialization in a module that lacks the element class on the classpath; corrupted className strings in serialized state.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/99735e47baf360a6. Report an issue: GitHub.