Skip to content

Commit 19257f4

Browse files
committed
Add javadoc notes on potential exception suppression in getBeansOfType
Closes gh-34629 (cherry picked from commit dc41ff5)
1 parent f06167e commit 19257f4

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -145,8 +145,6 @@ public interface ListableBeanFactory extends BeanFactory {
145145
* <p>Does not consider any hierarchy this factory may participate in.
146146
* Use BeanFactoryUtils' {@code beanNamesForTypeIncludingAncestors}
147147
* to include beans in ancestor factories too.
148-
* <p>Note: Does <i>not</i> ignore singleton beans that have been registered
149-
* by other means than bean definitions.
150148
* <p>This version of {@code getBeanNamesForType} matches all kinds of beans,
151149
* be it singletons, prototypes, or FactoryBeans. In most implementations, the
152150
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
@@ -176,8 +174,6 @@ public interface ListableBeanFactory extends BeanFactory {
176174
* <p>Does not consider any hierarchy this factory may participate in.
177175
* Use BeanFactoryUtils' {@code beanNamesForTypeIncludingAncestors}
178176
* to include beans in ancestor factories too.
179-
* <p>Note: Does <i>not</i> ignore singleton beans that have been registered
180-
* by other means than bean definitions.
181177
* <p>Bean names returned by this method should always return bean names <i>in the
182178
* order of definition</i> in the backend configuration, as far as possible.
183179
* @param type the generically typed class or interface to match
@@ -210,8 +206,6 @@ public interface ListableBeanFactory extends BeanFactory {
210206
* <p>Does not consider any hierarchy this factory may participate in.
211207
* Use BeanFactoryUtils' {@code beanNamesForTypeIncludingAncestors}
212208
* to include beans in ancestor factories too.
213-
* <p>Note: Does <i>not</i> ignore singleton beans that have been registered
214-
* by other means than bean definitions.
215209
* <p>This version of {@code getBeanNamesForType} matches all kinds of beans,
216210
* be it singletons, prototypes, or FactoryBeans. In most implementations, the
217211
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
@@ -239,8 +233,6 @@ public interface ListableBeanFactory extends BeanFactory {
239233
* <p>Does not consider any hierarchy this factory may participate in.
240234
* Use BeanFactoryUtils' {@code beanNamesForTypeIncludingAncestors}
241235
* to include beans in ancestor factories too.
242-
* <p>Note: Does <i>not</i> ignore singleton beans that have been registered
243-
* by other means than bean definitions.
244236
* <p>Bean names returned by this method should always return bean names <i>in the
245237
* order of definition</i> in the backend configuration, as far as possible.
246238
* @param type the class or interface to match, or {@code null} for all bean names
@@ -265,21 +257,24 @@ public interface ListableBeanFactory extends BeanFactory {
265257
* subclasses), judging from either bean definitions or the value of
266258
* {@code getObjectType} in the case of FactoryBeans.
267259
* <p><b>NOTE: This method introspects top-level beans only.</b> It does <i>not</i>
268-
* check nested beans which might match the specified type as well.
260+
* check nested beans which might match the specified type as well. Also, it
261+
* <b>suppresses exceptions for beans that are currently in creation in a circular
262+
* reference scenario:</b> typically, references back to the caller of this method.
269263
* <p>Does consider objects created by FactoryBeans, which means that FactoryBeans
270264
* will get initialized. If the object created by the FactoryBean doesn't match,
271265
* the raw FactoryBean itself will be matched against the type.
272266
* <p>Does not consider any hierarchy this factory may participate in.
273267
* Use BeanFactoryUtils' {@code beansOfTypeIncludingAncestors}
274268
* to include beans in ancestor factories too.
275-
* <p>Note: Does <i>not</i> ignore singleton beans that have been registered
276-
* by other means than bean definitions.
277269
* <p>This version of getBeansOfType matches all kinds of beans, be it
278270
* singletons, prototypes, or FactoryBeans. In most implementations, the
279271
* result will be the same as for {@code getBeansOfType(type, true, true)}.
280272
* <p>The Map returned by this method should always return bean names and
281273
* corresponding bean instances <i>in the order of definition</i> in the
282274
* backend configuration, as far as possible.
275+
* <p><b>Consider {@link #getBeanNamesForType(Class)} with selective {@link #getBean}
276+
* calls for specific bean names in preference to this Map-based retrieval method.</b>
277+
* Aside from lazy instantiation benefits, this also avoids any exception suppression.
283278
* @param type the class or interface to match, or {@code null} for all concrete beans
284279
* @return a Map with the matching beans, containing the bean names as
285280
* keys and the corresponding bean instances as values
@@ -295,7 +290,9 @@ public interface ListableBeanFactory extends BeanFactory {
295290
* subclasses), judging from either bean definitions or the value of
296291
* {@code getObjectType} in the case of FactoryBeans.
297292
* <p><b>NOTE: This method introspects top-level beans only.</b> It does <i>not</i>
298-
* check nested beans which might match the specified type as well.
293+
* check nested beans which might match the specified type as well. Also, it
294+
* <b>suppresses exceptions for beans that are currently in creation in a circular
295+
* reference scenario:</b> typically, references back to the caller of this method.
299296
* <p>Does consider objects created by FactoryBeans if the "allowEagerInit" flag is set,
300297
* which means that FactoryBeans will get initialized. If the object created by the
301298
* FactoryBean doesn't match, the raw FactoryBean itself will be matched against the
@@ -304,11 +301,12 @@ public interface ListableBeanFactory extends BeanFactory {
304301
* <p>Does not consider any hierarchy this factory may participate in.
305302
* Use BeanFactoryUtils' {@code beansOfTypeIncludingAncestors}
306303
* to include beans in ancestor factories too.
307-
* <p>Note: Does <i>not</i> ignore singleton beans that have been registered
308-
* by other means than bean definitions.
309304
* <p>The Map returned by this method should always return bean names and
310305
* corresponding bean instances <i>in the order of definition</i> in the
311306
* backend configuration, as far as possible.
307+
* <p><b>Consider {@link #getBeanNamesForType(Class)} with selective {@link #getBean}
308+
* calls for specific bean names in preference to this Map-based retrieval method.</b>
309+
* Aside from lazy instantiation benefits, this also avoids any exception suppression.
312310
* @param type the class or interface to match, or {@code null} for all concrete beans
313311
* @param includeNonSingletons whether to include prototype or scoped beans too
314312
* or just singletons (also applies to FactoryBeans)

0 commit comments

Comments
 (0)