{"record":{"id":"60efb09b3ca52a1c","repo":"spring-projects/spring-framework","slug":"sourcelist-is-required","errorCode":null,"errorMessage":"'sourceList' is required","messagePattern":"'sourceList' is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java","lineNumber":80,"sourceCode":"\t\t}\n\t\tif (!List.class.isAssignableFrom(targetListClass)) {\n\t\t\tthrow new IllegalArgumentException(\"'targetListClass' must implement [java.util.List]\");\n\t\t}\n\t\tthis.targetListClass = targetListClass;\n\t}\n\n\n\t@Override\n\t@SuppressWarnings(\"rawtypes\")\n\tpublic Class<List> getObjectType() {\n\t\treturn List.class;\n\t}\n\n\t@Override\n\t@SuppressWarnings(\"unchecked\")\n\tprotected List<Object> createInstance() {\n\t\tif (this.sourceList == null) {\n\t\t\tthrow new IllegalArgumentException(\"'sourceList' is required\");\n\t\t}\n\t\tList<Object> result = null;\n\t\tif (this.targetListClass != null) {\n\t\t\tresult = BeanUtils.instantiateClass(this.targetListClass);\n\t\t}\n\t\telse {\n\t\t\tresult = new ArrayList<>(this.sourceList.size());\n\t\t}\n\t\tClass<?> valueType = null;\n\t\tif (this.targetListClass != null) {\n\t\t\tvalueType = ResolvableType.forClass(this.targetListClass).asCollection().resolveGeneric();\n\t\t}\n\t\tif (valueType != null) {\n\t\t\tTypeConverter converter = getBeanTypeConverter();\n\t\t\tfor (Object elem : this.sourceList) {\n\t\t\t\tresult.add(converter.convertIfNecessary(elem, valueType));\n\t\t\t}\n\t\t}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java#L62-L98","documentation":"Thrown by ListFactoryBean.createInstance() when sourceList was never set. ListFactoryBean copies the provided source list into the target list instance, so without a source there is nothing to produce. This fires at bean creation (not init) time, i.e. when the List is first requested from the factory.","triggerScenarios":"A <bean class=\"ListFactoryBean\"> definition with no <property name=\"sourceList\"> child (often when using the bean for an empty list and assuming it defaults). Programmatic ListFactoryBean used without setSourceList. A <util:list> backed by ListFactoryBean where the inner elements are all omitted incorrectly.","commonSituations":"Forgetting to populate the list, intending an empty list but providing no element. XML where the <list> child was accidentally removed. Refactoring that dropped the sourceList property.","solutions":["Provide a source list: in XML add <property name=\"sourceList\"><list>...</list></property>; in code call fb.setSourceList(List.of(...)).","For an empty list, pass an empty list explicitly: fb.setSourceList(new ArrayList<>()) or <property name=\"sourceList\"><list/></property>.","If you do not need Spring-managed sharing, inject a plain List directly instead of ListFactoryBean."],"exampleFix":"// before (broken)\nListFactoryBean fb = new ListFactoryBean();\nfb.getObject();\n// after\nListFactoryBean fb = new ListFactoryBean();\nfb.setSourceList(List.of(\"a\", \"b\"));","handlingStrategy":"validation","validationCode":"if (sourceList == null) {\n    sourceList = List.of(); // or fail fast with a clear message\n}\nfactoryBean.setSourceList(sourceList);","typeGuard":"static boolean hasSourceList(ListFactoryBean fb) {\n    // sourceList has no public getter; track it at the call site\n    return true; // ensure setSourceList was invoked before getObject()\n}","tryCatchPattern":"try {\n    return fb.getObject();\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage().contains(\"sourceList\")) {\n        fb.setSourceList(List.of()); // provide empty default then retry\n        return fb.getObject();\n    }\n    throw ex;\n}","preventionTips":["Always call setSourceList, even with an empty list, when using ListFactoryBean programmatically.","Prefer <util:list> in XML which guarantees a source list is present.","Add a context-load integration test to surface missing-property errors early."],"tags":["spring","factory-bean","collection","configuration","missing-property"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}