1818
1919import java .lang .reflect .Member ;
2020import java .lang .reflect .Method ;
21- import java .util .Collections ;
21+ import java .util .HashSet ;
2222import java .util .Set ;
23- import java .util .concurrent .ConcurrentHashMap ;
2423
2524import org .springframework .beans .MutablePropertyValues ;
2625import org .springframework .beans .factory .config .BeanDefinition ;
4948@ SuppressWarnings ("serial" )
5049public class RootBeanDefinition extends AbstractBeanDefinition {
5150
52- private final Set <Member > externallyManagedConfigMembers =
53- Collections .newSetFromMap (new ConcurrentHashMap <Member , Boolean >(0 ));
54-
55- private final Set <String > externallyManagedInitMethods =
56- Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >(0 ));
57-
58- private final Set <String > externallyManagedDestroyMethods =
59- Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >(0 ));
51+ boolean allowCaching = true ;
6052
6153 private BeanDefinitionHolder decoratedDefinition ;
6254
63- boolean allowCaching = true ;
64-
6555 private volatile Class <?> targetType ;
6656
6757 boolean isFactoryMethodUnique = false ;
@@ -91,6 +81,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
9181 /** Package-visible field that indicates a before-instantiation post-processor having kicked in */
9282 volatile Boolean beforeInstantiationResolved ;
9383
84+ private Set <Member > externallyManagedConfigMembers ;
85+
86+ private Set <String > externallyManagedInitMethods ;
87+
88+ private Set <String > externallyManagedDestroyMethods ;
89+
9490
9591 /**
9692 * Create a new RootBeanDefinition, to be configured through its bean
@@ -175,8 +171,8 @@ public RootBeanDefinition(String beanClassName, ConstructorArgumentValues cargs,
175171 */
176172 public RootBeanDefinition (RootBeanDefinition original ) {
177173 super (original );
178- this .decoratedDefinition = original .decoratedDefinition ;
179174 this .allowCaching = original .allowCaching ;
175+ this .decoratedDefinition = original .decoratedDefinition ;
180176 this .targetType = original .targetType ;
181177 this .isFactoryMethodUnique = original .isFactoryMethodUnique ;
182178 }
@@ -203,6 +199,20 @@ public void setParentName(String parentName) {
203199 }
204200 }
205201
202+ /**
203+ * Register a target definition that is being decorated by this bean definition.
204+ */
205+ public void setDecoratedDefinition (BeanDefinitionHolder decoratedDefinition ) {
206+ this .decoratedDefinition = decoratedDefinition ;
207+ }
208+
209+ /**
210+ * Return the target definition that is being decorated by this bean definition, if any.
211+ */
212+ public BeanDefinitionHolder getDecoratedDefinition () {
213+ return this .decoratedDefinition ;
214+ }
215+
206216 /**
207217 * Specify the target type of this bean definition, if known in advance.
208218 */
@@ -245,37 +255,52 @@ public Method getResolvedFactoryMethod() {
245255 }
246256 }
247257
248-
249258 public void registerExternallyManagedConfigMember (Member configMember ) {
250- this .externallyManagedConfigMembers .add (configMember );
259+ synchronized (this .postProcessingLock ) {
260+ if (this .externallyManagedConfigMembers == null ) {
261+ this .externallyManagedConfigMembers = new HashSet <Member >(1 );
262+ }
263+ this .externallyManagedConfigMembers .add (configMember );
264+ }
251265 }
252266
253267 public boolean isExternallyManagedConfigMember (Member configMember ) {
254- return this .externallyManagedConfigMembers .contains (configMember );
268+ synchronized (this .postProcessingLock ) {
269+ return (this .externallyManagedConfigMembers != null &&
270+ this .externallyManagedConfigMembers .contains (configMember ));
271+ }
255272 }
256273
257274 public void registerExternallyManagedInitMethod (String initMethod ) {
258- this .externallyManagedInitMethods .add (initMethod );
275+ synchronized (this .postProcessingLock ) {
276+ if (this .externallyManagedInitMethods == null ) {
277+ this .externallyManagedInitMethods = new HashSet <String >(1 );
278+ }
279+ this .externallyManagedInitMethods .add (initMethod );
280+ }
259281 }
260282
261283 public boolean isExternallyManagedInitMethod (String initMethod ) {
262- return this .externallyManagedInitMethods .contains (initMethod );
284+ synchronized (this .postProcessingLock ) {
285+ return (this .externallyManagedInitMethods != null &&
286+ this .externallyManagedInitMethods .contains (initMethod ));
287+ }
263288 }
264289
265290 public void registerExternallyManagedDestroyMethod (String destroyMethod ) {
266- this .externallyManagedDestroyMethods .add (destroyMethod );
291+ synchronized (this .postProcessingLock ) {
292+ if (this .externallyManagedDestroyMethods == null ) {
293+ this .externallyManagedDestroyMethods = new HashSet <String >(1 );
294+ }
295+ this .externallyManagedDestroyMethods .add (destroyMethod );
296+ }
267297 }
268298
269299 public boolean isExternallyManagedDestroyMethod (String destroyMethod ) {
270- return this .externallyManagedDestroyMethods .contains (destroyMethod );
271- }
272-
273- public void setDecoratedDefinition (BeanDefinitionHolder decoratedDefinition ) {
274- this .decoratedDefinition = decoratedDefinition ;
275- }
276-
277- public BeanDefinitionHolder getDecoratedDefinition () {
278- return this .decoratedDefinition ;
300+ synchronized (this .postProcessingLock ) {
301+ return (this .externallyManagedDestroyMethods != null &&
302+ this .externallyManagedDestroyMethods .contains (destroyMethod ));
303+ }
279304 }
280305
281306
0 commit comments