{"id":"28206bbc61c40741","repo":"spring-projects/spring-framework","slug":"specify-targetclass-or-targetobject-in-combination","errorCode":null,"errorMessage":"Specify targetClass or targetObject in combination with targetField","messagePattern":"Specify targetClass or targetObject in combination with targetField","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java","lineNumber":169,"sourceCode":"\t\tthis.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));\n\t}\n\n\t@Override\n\tpublic void setBeanClassLoader(ClassLoader classLoader) {\n\t\tthis.beanClassLoader = classLoader;\n\t}\n\n\n\t@Override\n\t@SuppressWarnings(\"NullAway\") // Dataflow analysis limitation\n\tpublic void afterPropertiesSet() throws ClassNotFoundException, NoSuchFieldException {\n\t\tif (this.targetClass != null && this.targetObject != null) {\n\t\t\tthrow new IllegalArgumentException(\"Specify either targetClass or targetObject, not both\");\n\t\t}\n\n\t\tif (this.targetClass == null && this.targetObject == null) {\n\t\t\tif (this.targetField != null) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Specify targetClass or targetObject in combination with targetField\");\n\t\t\t}\n\n\t\t\t// If no other property specified, consider bean name as static field expression.\n\t\t\tif (this.staticField == null) {\n\t\t\t\tthis.staticField = this.beanName;\n\t\t\t\tAssert.state(this.staticField != null, \"No target field specified\");\n\t\t\t}\n\n\t\t\t// Try to parse static field into class and field.\n\t\t\tint lastDotIndex = this.staticField.lastIndexOf('.');\n\t\t\tif (lastDotIndex == -1 || lastDotIndex == this.staticField.length()) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"staticField must be a fully qualified class plus static field name: \" +\n\t\t\t\t\t\t\"for example, 'example.MyExampleClass.MY_EXAMPLE_FIELD'\");\n\t\t\t}\n\t\t\tString className = this.staticField.substring(0, lastDotIndex);\n\t\t\tString fieldName = this.staticField.substring(lastDotIndex + 1);","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java#L151-L187","documentation":"Error \"Specify targetClass or targetObject in combination with targetField\" thrown in spring-projects/spring-framework.","triggerScenarios":"Thrown at spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java:169 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}