{"record":{"id":"7f11ec4794ab53f0","repo":"spring-projects/spring-framework","slug":"argument-type-mismatch-expected","errorCode":null,"errorMessage":"Argument type mismatch: expected '","messagePattern":"Argument type mismatch: expected '","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java","lineNumber":47,"sourceCode":" * @since 6.0\n * @see BeanInstanceSupplier\n * @see AutowiredMethodArgumentsResolver\n */\n@FunctionalInterface\npublic interface AutowiredArguments {\n\n\t/**\n\t * Return the resolved argument at the specified index.\n\t * @param <T> the type of the argument\n\t * @param index the argument index\n\t * @param requiredType the required argument type\n\t * @return the argument\n\t */\n\t@SuppressWarnings(\"unchecked\")\n\tdefault <T> @Nullable T get(int index, Class<T> requiredType) {\n\t\tObject value = getObject(index);\n\t\tif (!ClassUtils.isAssignableValue(requiredType, value)) {\n\t\t\tthrow new IllegalArgumentException(\"Argument type mismatch: expected '\" +\n\t\t\t\t\trequiredType.getTypeName() + \"' for value [\" + value + \"]\");\n\t\t}\n\t\treturn (T) value;\n\t}\n\n\t/**\n\t * Return the resolved argument at the specified index.\n\t * @param <T> the type of the argument\n\t * @param index the argument index\n\t * @return the argument\n\t */\n\t@SuppressWarnings(\"unchecked\")\n\tdefault <T> @Nullable T get(int index) {\n\t\treturn (T) getObject(index);\n\t}\n\n\t/**\n\t * Return the resolved argument at the specified index.","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java#L29-L65","documentation":"Thrown by AutowiredArguments.get(int index, Class<T> requiredType) when the resolved argument at the given index is not assignable to the requested type. AutowiredArguments is part of the AOT (Ahead-of-Time) processing infrastructure (since Spring 6.0); it represents pre-resolved constructor or method arguments used by BeanInstanceSupplier in native/GraalVM scenarios. The type check at line 46 uses ClassUtils.isAssignableValue().","triggerScenarios":"Calling autowiredArguments.get(0, SomeType.class) where the actual resolved argument value's runtime type is not assignable to SomeType. This is typically triggered by AOT-generated code or BeanInstanceSupplier where the pre-resolved arguments array was constructed with values whose types don't match the declared parameter types.","commonSituations":"AOT processing mismatch where the generated BeanInstanceSupplier passes arguments of the wrong type. Custom BeanRegistrationAotProcessor producing incorrect AutowiredArguments. Spring Boot native image compilation where bean definitions changed between AOT and runtime. Generic type erasure causing an assignability check to fail at runtime.","solutions":["Ensure the AutowiredArguments array passed to BeanInstanceSupplier.of() contains values whose types match the constructor/method parameter types in order.","Use the type-unsafe get(int index) overload if you are certain of the type and want to avoid the check, then cast manually.","Regenerate AOT artifacts (clean and rebuild) if the bean signatures have changed to eliminate stale generated code."],"exampleFix":"// before\nAutowiredArguments args = AutowiredArguments.of(\n    new Object[]{ \"not-a-number\" });\nInteger value = args.get(0, Integer.class); // throws\n\n// after\nAutowiredArguments args = AutowiredArguments.of(\n    new Object[]{ 42 });\nInteger value = args.get(0, Integer.class); // ok","handlingStrategy":"type-guard","validationCode":"// Before calling get(index, type), check assignability\nObject raw = args.toArray()[index];\nif (raw != null && !requiredType.isAssignableFrom(raw.getClass())) {\n    throw new IllegalStateException(\n        \"Argument at index \" + index + \" is \" + raw.getClass()\n        + \" not \" + requiredType);\n}\nT result = requiredType.cast(raw);","typeGuard":"// Type guard for AutowiredArguments\nstatic <T> boolean isArgumentType(\n        AutowiredArguments args, int index, Class<T> requiredType) {\n    Object value = args.getObject(index);\n    return value == null || requiredType.isAssignableFrom(value.getClass());\n}","tryCatchPattern":"try {\n    T value = args.get(index, requiredType);\n} catch (IllegalArgumentException ex) {\n    // message: \"Argument type mismatch: expected '...'\"\n    Object actual = args.getObject(index);\n    // handle: regenerate AOT code, fix argument resolution, or cast manually\n}","preventionTips":["Ensure AutowiredArguments arrays are constructed with values whose types match declared parameters.","Regenerate AOT artifacts (mvn clean + spring-boot:process-aot) after changing bean constructors.","Use the type-unsafe get(int index) overload with manual casting if types are known and stable."],"tags":["spring","aot","type-mismatch","native"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}