1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
70
70
*/
71
71
public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {
72
72
73
+ /** Maximum number of suppressed exceptions to preserve. */
74
+ private static final int SUPPRESSED_EXCEPTIONS_LIMIT = 100 ;
75
+
76
+
73
77
/** Cache of singleton objects: bean name to bean instance. */
74
78
private final Map <String , Object > singletonObjects = new ConcurrentHashMap <>(256 );
75
79
@@ -90,7 +94,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
90
94
private final Set <String > inCreationCheckExclusions =
91
95
Collections .newSetFromMap (new ConcurrentHashMap <>(16 ));
92
96
93
- /** List of suppressed Exceptions, available for associating related causes. */
97
+ /** Collection of suppressed Exceptions, available for associating related causes. */
94
98
@ Nullable
95
99
private Set <Exception > suppressedExceptions ;
96
100
@@ -253,13 +257,17 @@ public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
253
257
}
254
258
255
259
/**
256
- * Register an Exception that happened to get suppressed during the creation of a
260
+ * Register an exception that happened to get suppressed during the creation of a
257
261
* singleton bean instance, e.g. a temporary circular reference resolution problem.
262
+ * <p>The default implementation preserves any given exception in this registry's
263
+ * collection of suppressed exceptions, up to a limit of 100 exceptions, adding
264
+ * them as related causes to an eventual top-level {@link BeanCreationException}.
258
265
* @param ex the Exception to register
266
+ * @see BeanCreationException#getRelatedCauses()
259
267
*/
260
268
protected void onSuppressedException (Exception ex ) {
261
269
synchronized (this .singletonObjects ) {
262
- if (this .suppressedExceptions != null ) {
270
+ if (this .suppressedExceptions != null && this . suppressedExceptions . size () < SUPPRESSED_EXCEPTIONS_LIMIT ) {
263
271
this .suppressedExceptions .add (ex );
264
272
}
265
273
}
0 commit comments