{"id":"0aa49719813fc335","repo":"spring-projects/spring-framework","slug":"argument-type-mismatch-expected-for-value","errorCode":null,"errorMessage":"Argument type mismatch: expected '{}' for value [{}]","messagePattern":"Argument type mismatch: expected '(.+?)' for value \\[(.+?)\\]","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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java#L29-L65","documentation":"AutowiredArguments.get(index, requiredType) is used by AOT-generated BeanInstanceSupplier code to fetch a resolved autowired argument and cast it to the type the generated code expects. If the runtime-resolved value is not assignable to requiredType (validated via ClassUtils.isAssignableValue), an IllegalArgumentException is thrown - a sign that the AOT-time argument shape disagrees with runtime resolution.","triggerScenarios":"AOT processing captured the constructor/factory-method parameter types, but at runtime the bean factory resolved an argument whose type no longer matches (different bean implementation, widened type, null where a primitive is required).","commonSituations":"Running AOT-optimized code against a classpath that differs from build time (bean implementation swapped), a bean returning a subtype that widened during a dependency upgrade, or a configuration where the autowired candidate changed type between AOT and runtime.","solutions":["Regenerate the AOT artifacts (spring-boot-maven-plugin process-aot / native build) after any bean/dependency change so captured argument types match runtime.","Ensure the runtime classpath is identical to the AOT classpath (no stale or overridden beans).","Check that the bean supplying the argument is of the expected type - fix the conflicting bean definition."],"exampleFix":"// before: AOT generated for ctor(Service s) but runtime bean is now LegacyService\n// after: rebuild AOT artifacts and align runtime classpath\n// mvn -Pnative spring-boot:process-aot","handlingStrategy":"validation","validationCode":"for (int i = 0; i < args.toArray().length; i++) {\n  Object v = args.getObject(i);\n  Class<?> expected = executable.getParameters()[i].getType();\n  if (!ClassUtils.isAssignableValue(expected, v)) {\n    throw new IllegalStateException(\"arg \" + i + \" \" + (v==null?\"null\":v.getClass()) + \" !<= \" + expected);\n  }\n}","typeGuard":"boolean argCompatible(Class<?> expected, @Nullable Object value) {\n  return ClassUtils.isAssignableValue(expected, value);\n}","tryCatchPattern":null,"preventionTips":["Always regenerate AOT artifacts (process-aot) after bean or dependency changes.","Run AOT and runtime on the same classpath and versions.","Treat any mismatched-argument AOT error as a stale-build signal first."],"tags":["spring","aot","native","type-mismatch","autowiring"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}