{"record":{"id":"db881117418ef698","repo":"spring-projects/spring-framework","slug":"specified-parameter-type","errorCode":null,"errorMessage":"Specified parameter type [","messagePattern":"Specified parameter type \\[","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java","lineNumber":239,"sourceCode":"\t\t\t}\n\t\t\telse {\n\t\t\t\treturn ((Method) this.member).getParameterTypes()[0];\n\t\t\t}\n\t\t}\n\n\t\tprotected final void checkResourceType(Class<?> resourceType) {\n\t\t\tif (this.isField) {\n\t\t\t\tClass<?> fieldType = ((Field) this.member).getType();\n\t\t\t\tif (!(resourceType.isAssignableFrom(fieldType) || fieldType.isAssignableFrom(resourceType))) {\n\t\t\t\t\tthrow new IllegalStateException(\"Specified field type [\" + fieldType +\n\t\t\t\t\t\t\t\"] is incompatible with resource type [\" + resourceType.getName() + \"]\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tClass<?> paramType =\n\t\t\t\t\t\t(this.pd != null ? this.pd.getPropertyType() : ((Method) this.member).getParameterTypes()[0]);\n\t\t\t\tif (!(resourceType.isAssignableFrom(paramType) || paramType.isAssignableFrom(resourceType))) {\n\t\t\t\t\tthrow new IllegalStateException(\"Specified parameter type [\" + paramType +\n\t\t\t\t\t\t\t\"] is incompatible with resource type [\" + resourceType.getName() + \"]\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Whether the property values should be injected.\n\t\t * @param pvs property values to check\n\t\t * @return whether the property values should be injected\n\t\t * @since 6.0.10\n\t\t */\n\t\tprotected boolean shouldInject(@Nullable PropertyValues pvs) {\n\t\t\tif (this.isField) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn !checkPropertySkipping(pvs);\n\t\t}\n","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java#L221-L257","documentation":"Thrown by InjectionMetadata.InjectedElement.checkResourceType() when the parameter type of an injected method or property setter is incompatible with the resolved resource type — checked at line 238. This is the method/setter counterpart of error 216 which covers fields.","triggerScenarios":"A setter method or property annotated for injection has a parameter whose type is incompatible with the resolved bean — neither assignable in either direction. For example, @Resource on setFoo(Bar bar) where the named resource is of type Baz.","commonSituations":"@Resource(name=...) on a setter where the named bean's type differs from the parameter type. Changing a setter parameter type without updating the bean type. Generic type erasure causing assignability failure at runtime.","solutions":["Ensure the setter/method parameter type is compatible with the actual bean type (assignable in at least one direction).","If using @Resource by name, verify the named bean's type matches the parameter type.","Update the parameter type or switch to a compatible bean."],"exampleFix":"// before\n@Resource(name = \"emailService\")\npublic void setService(SmsService sms) { ... } // type mismatch\n\n// after\n@Resource(name = \"emailService\")\npublic void setService(EmailService email) { ... }","handlingStrategy":"validation","validationCode":"// Verify setter parameter type compatibility before injection\nfor (Method m : beanClass.getDeclaredMethods()) {\n    if (m.isAnnotationPresent(Resource.class) && m.getParameterCount() == 1) {\n        Resource r = m.getAnnotation(Resource.class);\n        Class<?> paramType = m.getParameterTypes()[0];\n        if (!r.name().isEmpty() && beanFactory.containsBean(r.name())) {\n            Class<?> beanType = beanFactory.getType(r.name());\n            if (beanType != null\n                    && !paramType.isAssignableFrom(beanType)\n                    && !beanType.isAssignableFrom(paramType)) {\n                throw new IllegalStateException(\n                    \"Setter param type \" + paramType + \" incompatible with bean \" + r.name());\n            }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure @Resource setter parameter types match the named bean type.","Prefer constructor-based @Autowired for type safety over name-based @Resource setters.","Run a startup bean-dependency validation test to catch type mismatches early."],"tags":["spring","injection","type-mismatch","resource"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}