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:
@@ -19,7 +19,6 @@ package org.springframework.web.context.request;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.config.Scope;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstract {@link Scope} implementation that reads from a particular scope
|
||||
@@ -44,7 +43,6 @@ public abstract class AbstractRequestAttributesScope implements Scope {
|
||||
Object scopedObject = attributes.getAttribute(name, getScope());
|
||||
if (scopedObject == null) {
|
||||
scopedObject = objectFactory.getObject();
|
||||
Assert.state(scopedObject != null, "Scoped object resolved to null");
|
||||
attributes.setAttribute(name, scopedObject, getScope());
|
||||
// Retrieve object again, registering it for implicit session attribute updates.
|
||||
// As a bonus, we also allow for potential decoration at the getAttribute level.
|
||||
|
||||
@@ -68,7 +68,6 @@ public class ServletContextScope implements Scope, DisposableBean {
|
||||
Object scopedObject = this.servletContext.getAttribute(name);
|
||||
if (scopedObject == null) {
|
||||
scopedObject = objectFactory.getObject();
|
||||
Assert.state(scopedObject != null, "Scoped object resolved to null");
|
||||
this.servletContext.setAttribute(name, scopedObject);
|
||||
}
|
||||
return scopedObject;
|
||||
|
||||
Reference in New Issue
Block a user