Enforce non-null value from getBean and at injection points

Bean-derived null values may still get passed into bean properties and injection points but only if those are declared as non-required. Note that getBean will never return null; a manual bean.equals(null) / "null".equals(bean.toString()) check identifies expected null values now.  This will only ever happen with custom FactoryBeans or factory methods returning null - and since all common cases are handled by autowiring or bean property values in bean definitions, there should be no need to ever manually check for such a null value received from getBean.

Issue: SPR-15829
This commit is contained in:
Juergen Hoeller
2017-08-18 00:11:35 +02:00
parent 10dcaa9bf6
commit b94302b5bd
30 changed files with 344 additions and 204 deletions

View File

@@ -57,6 +57,16 @@
<property name="friends">
<bean name="otb.spouse" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
</property>
</bean>
</bean>
<bean id="tbWithNullReference" class="org.springframework.tests.sample.beans.TestBean">
<property name="spouse" ref="tb.spouse.spouse"/>
</bean>
<bean id="tbWithInnerNull" class="org.springframework.tests.sample.beans.TestBean">
<property name="spouse">
<bean name="tb.spouse.spouse" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
</property>
</bean>
</beans>