{"record":{"id":"0938f9fe2507c50a","repo":"spring-projects/spring-framework","slug":"retrieval-with-arguments-not-supported-for-custom","errorCode":null,"errorMessage":"Retrieval with arguments not supported -for custom ObjectProvider classes, implement getObject(Object...) for your purposes","messagePattern":"Retrieval with arguments not supported -for custom ObjectProvider classes, implement getObject\\(Object\\.\\.\\.\\) for your purposes","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java","lineNumber":109,"sourceCode":"\t\tT result = it.next();\n\t\tif (it.hasNext()) {\n\t\t\tthrow new NoUniqueBeanDefinitionException(Object.class, 2, \"more than 1 matching bean\");\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Return an instance (possibly shared or independent) of the object\n\t * managed by this factory.\n\t * <p>Allows for specifying explicit construction arguments, along the\n\t * lines of {@link BeanFactory#getBean(String, Object...)}.\n\t * @param args arguments to use when creating a corresponding instance\n\t * @return an instance of the bean\n\t * @throws BeansException in case of creation errors\n\t * @see #getObject()\n\t */\n\tdefault T getObject(@Nullable Object... args) throws BeansException {\n\t\tthrow new UnsupportedOperationException(\"Retrieval with arguments not supported -\" +\n\t\t\t\t\"for custom ObjectProvider classes, implement getObject(Object...) for your purposes\");\n\t}\n\n\t/**\n\t * Return an instance (possibly shared or independent) of the object\n\t * managed by this factory.\n\t * @return an instance of the bean, or {@code null} if not available\n\t * @throws BeansException in case of creation errors\n\t * @see #getObject()\n\t */\n\tdefault @Nullable T getIfAvailable() throws BeansException {\n\t\ttry {\n\t\t\treturn getObject();\n\t\t}\n\t\tcatch (NoUniqueBeanDefinitionException ex) {\n\t\t\tthrow ex;\n\t\t}\n\t\tcatch (NoSuchBeanDefinitionException ex) {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java#L91-L127","documentation":"UnsupportedOperationException from the default ObjectProvider.getObject(Object... args) at line 109. The interface ships a no-arg getObject() default but does NOT implement the args variant; only the framework's internal ContextBeanProvider-style implementations support retrieval with explicit construction arguments. Custom ObjectProvider subclasses must override it.","triggerScenarios":"Calling objectProvider.getObject(args...) on a hand-rolled ObjectProvider implementation, or on a default-method-only test double, that did not override the args overload.","commonSituations":"Unit tests faking an ObjectProvider; library code that accepts ObjectProvider from a caller and tries to pass constructor args; extending ObjectProvider without realising getObject(args) is not defaulted.","solutions":["Override getObject(Object... args) in your custom ObjectProvider to perform the actual retrieval.","Avoid the args overload; use getObject() and configure the bean definition with the desired constructor args instead.","Inject the BeanFactory directly and use getBean(name, args) when runtime args are essential."],"exampleFix":"// before\npublic class TestProvider<T> implements ObjectProvider<T> {\n    // only getObject() implemented; getObject(args) -> UnsupportedOperationException\n}\n\n// after\npublic T getObject(Object... args) {\n    return beanFactory.getBean(type, args);\n}","handlingStrategy":"validation","validationCode":"// Detect the unsupported args path before calling\nMethod m = provider.getClass().getMethod(\"getObject\", Object[].class);\nif (m.isDefault()) {\n    throw new UnsupportedOperationException(\"provider does not support getObject(args)\");\n}","typeGuard":"static boolean supportsArgsLookup(ObjectProvider<?> p) {\n    try {\n        return !p.getClass().getMethod(\"getObject\", Object[].class).isDefault();\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Override getObject(Object...) in any custom ObjectProvider subclass.","Prefer injecting BeanFactory and using getBean(name, args) for runtime args.","Avoid the args overload unless your provider documents support."],"tags":["dependency-injection","object-provider","unsupported-operation"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}