{"record":{"id":"2c167b8330fc6594","repo":"spring-projects/spring-framework","slug":"invalid-value-for-custom-qualifier-type-need","errorCode":null,"errorMessage":"Invalid value [{}] for custom qualifier type: needs to be Class or String.","messagePattern":"Invalid value \\[(.+?)\\] for custom qualifier type: needs to be Class or String\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java","lineNumber":111,"sourceCode":"\t\t\tif (!(beanFactory instanceof DefaultListableBeanFactory dlbf)) {\n\t\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\t\"CustomAutowireConfigurer needs to operate on a DefaultListableBeanFactory\");\n\t\t\t}\n\t\t\tif (!(dlbf.getAutowireCandidateResolver() instanceof QualifierAnnotationAutowireCandidateResolver)) {\n\t\t\t\tdlbf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());\n\t\t\t}\n\t\t\tQualifierAnnotationAutowireCandidateResolver resolver =\n\t\t\t\t\t(QualifierAnnotationAutowireCandidateResolver) dlbf.getAutowireCandidateResolver();\n\t\t\tfor (Object value : this.customQualifierTypes) {\n\t\t\t\tClass<? extends Annotation> customType = null;\n\t\t\t\tif (value instanceof Class) {\n\t\t\t\t\tcustomType = (Class<? extends Annotation>) value;\n\t\t\t\t}\n\t\t\t\telse if (value instanceof String className) {\n\t\t\t\t\tcustomType = (Class<? extends Annotation>) ClassUtils.resolveClassName(className, this.beanClassLoader);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Invalid value [\" + value + \"] for custom qualifier type: needs to be Class or String.\");\n\t\t\t\t}\n\t\t\t\tif (!Annotation.class.isAssignableFrom(customType)) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Qualifier type [\" + customType.getName() + \"] needs to be annotation type\");\n\t\t\t\t}\n\t\t\t\tresolver.addQualifierType(customType);\n\t\t\t}\n\t\t}\n\t}\n\n}\n","sourceCodeStart":93,"sourceCodeEnd":124,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java#L93-L124","documentation":"Thrown by CustomAutowireConfigurer when iterating customQualifierTypes and encountering an element that is neither a Class nor a String. The setCustomQualifierTypes(Set<?>) accepts arbitrary objects, but each must be a Class literal or a fully-qualified class name String.","triggerScenarios":"Configuring customQualifierTypes with values that are not Class or String — e.g., an Integer, an enum, or an Annotation instance passed into the set via XML property injection or programmatic configuration.","commonSituations":"XML misconfiguration where <value> elements are parsed to non-string types. Programmatic configuration where a wrong type is added to the set. A typo in XML causing a value tag to be interpreted as a non-string type.","solutions":["Ensure every element in customQualifierTypes is either a Class object or a fully-qualified annotation class name String.","In XML, use <value>com.example.MyQualifier</value> (String) or <value type=\"java.lang.Class\">com.example.MyQualifier</value>.","Audit the set contents at configuration time."],"exampleFix":"<!-- before -->\n<bean class=\"...CustomAutowireConfigurer\">\n  <property name=\"customQualifierTypes\">\n    <set>\n      <value>12345</value> <!-- invalid -->\n    </set>\n  </property>\n</bean>\n\n<!-- after -->\n<bean class=\"...CustomAutowireConfigurer\">\n  <property name=\"customQualifierTypes\">\n    <set>\n      <value>com.example.MyQualifierAnnotation</value>\n    </set>\n  </property>\n</bean>","handlingStrategy":"validation","validationCode":"// Validate all custom qualifier type entries before passing to configurer\nfor (Object value : customQualifierTypes) {\n    if (!(value instanceof Class) && !(value instanceof String)) {\n        throw new IllegalArgumentException(\n            \"Invalid custom qualifier type entry: \" + value\n            + \" (must be Class or String)\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use Class objects or fully-qualified class name Strings in customQualifierTypes.","In XML, use plain <value> elements with string class names.","Validate the set programmatically before calling setCustomQualifierTypes."],"tags":["spring","custom-autowire","configuration","type-mismatch"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}