Skip to content

Commit 3d297b1

Browse files
committed
NamedBeanHolder enforces bean name
Issue: SPR-7549
1 parent d9d84ff commit 3d297b1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.beans.factory.config;
1818

1919
import org.springframework.beans.factory.NamedBean;
20+
import org.springframework.util.Assert;
2021

2122
/**
2223
* A simple holder for a given bean name plus bean instance.
@@ -34,20 +35,26 @@ public class NamedBeanHolder<T> implements NamedBean {
3435

3536
/**
3637
* Create a new holder for the given bean name plus instance.
38+
* @param beanName the name of the bean
39+
* @param beanInstance the corresponding bean instance
3740
*/
3841
public NamedBeanHolder(String beanName, T beanInstance) {
42+
Assert.notNull(beanName, "Bean name must not be null");
3943
this.beanName = beanName;
4044
this.beanInstance = beanInstance;
4145
}
4246

4347

48+
/**
49+
* Return the name of the bean (never {@code null}).
50+
*/
4451
@Override
4552
public String getBeanName() {
4653
return this.beanName;
4754
}
4855

4956
/**
50-
* Return the corresponding bean instance.
57+
* Return the corresponding bean instance (can be {@code null}).
5158
*/
5259
public T getBeanInstance() {
5360
return this.beanInstance;

0 commit comments

Comments
 (0)