{"record":{"id":"675bece8560b9d06","repo":"spring-projects/spring-framework","slug":"only-supports-includenonsingletons-true-by-default","errorCode":null,"errorMessage":"Only supports includeNonSingletons=true by default","messagePattern":"Only supports includeNonSingletons=true by default","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java","lineNumber":307,"sourceCode":"\tdefault Stream<T> orderedStream(Predicate<Class<?>> customFilter) {\n\t\treturn orderedStream(customFilter, true);\n\t}\n\n\t/**\n\t * Return a custom-filtered {@link Stream} over all matching object instances,\n\t * without specific ordering guarantees (but typically in registration order).\n\t * @param customFilter a custom type filter for selecting beans among the raw\n\t * bean type matches (or {@link #UNFILTERED} for all raw type matches without\n\t * any default filtering)\n\t * @param includeNonSingletons whether to include prototype or scoped beans too\n\t * or just singletons (also applies to FactoryBeans)\n\t * @since 6.2.5\n\t * @see #stream(Predicate)\n\t * @see #orderedStream(Predicate, boolean)\n\t */\n\tdefault Stream<T> stream(Predicate<Class<?>> customFilter, boolean includeNonSingletons) {\n\t\tif (!includeNonSingletons) {\n\t\t\tthrow new UnsupportedOperationException(\"Only supports includeNonSingletons=true by default\");\n\t\t}\n\t\treturn stream().filter(obj -> customFilter.test(obj.getClass()));\n\t}\n\n\t/**\n\t * Return a custom-filtered {@link Stream} over all matching object instances,\n\t * pre-ordered according to the factory's common order comparator.\n\t * @param customFilter a custom type filter for selecting beans among the raw\n\t * bean type matches (or {@link #UNFILTERED} for all raw type matches without\n\t * any default filtering)\n\t * @param includeNonSingletons whether to include prototype or scoped beans too\n\t * or just singletons (also applies to FactoryBeans)\n\t * @since 6.2.5\n\t * @see #orderedStream()\n\t * @see #stream(Predicate)\n\t */\n\tdefault Stream<T> orderedStream(Predicate<Class<?>> customFilter, boolean includeNonSingletons) {\n\t\tif (!includeNonSingletons) {","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java#L289-L325","documentation":"UnsupportedOperationException from the default ObjectProvider.stream(Predicate, boolean) at line 307 when includeNonSingletons is false. Since 6.2.5 this overload exists but the default implementation can only enumerate all matches (singletons + non-singletons); it cannot restrict to singletons, so passing false is rejected.","triggerScenarios":"Calling objectProvider.stream(filter, false) or .stream(UNFILTERED, false) on a default-method ObjectProvider (or any impl that does not override this overload) intending to iterate only singleton beans.","commonSituations":"Trying to mirror ListableBeanFactory.getBeansOfType(includeNonSingletons=false) semantics via an ObjectProvider; custom ObjectProvider subclasses that do not implement the boolean overload.","solutions":["Call stream(filter) / stream(filter, true) (the default includeNonSingletons=true path) and filter singletons yourself via beanFactory.isSingleton(name).","Override stream(Predicate, boolean) in your custom ObjectProvider to honour the flag.","Use ListableBeanFactory.getBeansOfType(type, false, true) directly when singleton-only enumeration is required."],"exampleFix":"// before\nprovider.stream(filter, false); // UnsupportedOperationException\n\n// after\nprovider.stream(filter)\n        .filter(o -> beanFactory.isSingleton(getBeanName(o)));","handlingStrategy":"validation","validationCode":"// Only call the boolean overload with includeNonSingletons=true on default impls\nif (!includeNonSingletons && !providerOverridesStream(provider, false)) {\n    throw new UnsupportedOperationException(\"provider cannot restrict to singletons\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to includeNonSingletons=true on the Predicate overloads.","Post-filter singletons via beanFactory.isSingleton(name).","Use ListableBeanFactory.getBeansOfType(type, false, true) for singleton-only enumeration."],"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"}