{"record":{"id":"a8c651aff3e28fbc","repo":"spring-projects/spring-framework","slug":"either-requiredtype-or-propertypath-is-required","errorCode":null,"errorMessage":"Either requiredType or propertyPath is required","messagePattern":"Either requiredType or propertyPath is required","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java","lineNumber":308,"sourceCode":"\t\ttarget.configValueEditorsActive = this.configValueEditorsActive;\n\t\ttarget.defaultEditors = this.defaultEditors;\n\t\ttarget.overriddenDefaultEditors = this.overriddenDefaultEditors;\n\t}\n\n\n\t//---------------------------------------------------------------------\n\t// Management of custom editors\n\t//---------------------------------------------------------------------\n\n\t@Override\n\tpublic void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {\n\t\tregisterCustomEditor(requiredType, null, propertyEditor);\n\t}\n\n\t@Override\n\tpublic void registerCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath, PropertyEditor propertyEditor) {\n\t\tif (requiredType == null && propertyPath == null) {\n\t\t\tthrow new IllegalArgumentException(\"Either requiredType or propertyPath is required\");\n\t\t}\n\t\tif (propertyPath != null) {\n\t\t\tif (this.customEditorsForPath == null) {\n\t\t\t\tthis.customEditorsForPath = new LinkedHashMap<>(16);\n\t\t\t}\n\t\t\tthis.customEditorsForPath.put(propertyPath, new CustomEditorHolder(propertyEditor, requiredType));\n\t\t}\n\t\telse {\n\t\t\tif (this.customEditors == null) {\n\t\t\t\tthis.customEditors = new LinkedHashMap<>(16);\n\t\t\t}\n\t\t\tthis.customEditors.put(requiredType, propertyEditor);\n\t\t\tthis.customEditorCache = null;\n\t\t}\n\t}\n\n\t@Override\n\tpublic @Nullable PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath) {","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java#L290-L326","documentation":"IllegalArgumentException from PropertyEditorRegistrySupport.registerCustomEditor when both requiredType and propertyPath are null. A custom editor must be scoped either by target type or by a specific property path; registering one with neither dimension is meaningless and rejected.","triggerScenarios":"Calling registry.registerCustomEditor(null, null, myEditor) — the (Class, String, PropertyEditor) overload with both leading arguments null. Happens in custom ConfigurableBeanFactory setups or tests that build editors programmatically.","commonSituations":"Misunderstanding the overload resolution (calling registerCustomEditor(null, editor) is allowed, but registerCustomEditor(null, null, editor) is not); passing null defensively; copy-paste from a generic editor registration helper.","solutions":["Pass the target type: registerCustomEditor(MyType.class, null, editor).","Or pass the property path: registerCustomEditor(null, \"bean.prop\", editor).","Prefer the two-argument overload registerCustomEditor(MyType.class, editor) when scoping by type."],"exampleFix":"// before\nregistry.registerCustomEditor(null, null, new MyEditor());\n\n// after\nregistry.registerCustomEditor(MyType.class, null, new MyEditor());","handlingStrategy":"validation","validationCode":"// Validate before registering an editor\nif (requiredType == null && propertyPath == null) {\n    throw new IllegalArgumentException(\"Supply requiredType or propertyPath\");\n}\nregistry.registerCustomEditor(requiredType, propertyPath, editor);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the two-arg registerCustomEditor(Class, editor) overload for type-scoped editors.","Centralise editor registration in one @PostConstruct / @InitBinder so null args are obvious.","Never pass both nulls defensively — pick a scope explicitly."],"tags":["property-editor","validation","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}