Refine null-safety in the spring-beans module
Closes gh-34152
This commit is contained in:
@@ -98,7 +98,8 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
|
||||
private boolean configValueEditorsActive = false;
|
||||
|
||||
private @Nullable Map<Class<?>, PropertyEditor> defaultEditors;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Map<Class<?>, PropertyEditor> defaultEditors;
|
||||
|
||||
private @Nullable Map<Class<?>, PropertyEditor> overriddenDefaultEditors;
|
||||
|
||||
@@ -171,7 +172,6 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @return the default editor, or {@code null} if none found
|
||||
* @see #registerDefaultEditors
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
public @Nullable PropertyEditor getDefaultEditor(Class<?> requiredType) {
|
||||
if (!this.defaultEditorsActive) {
|
||||
return null;
|
||||
|
||||
@@ -100,9 +100,11 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public BeanDefinitionStoreException(
|
||||
@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String msg, @Nullable Throwable cause) {
|
||||
|
||||
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg,
|
||||
super(msg == null ?
|
||||
"Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription :
|
||||
"Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg,
|
||||
cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
|
||||
@@ -74,7 +74,8 @@ public abstract class AbstractFactoryBean<T>
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private @Nullable T singletonInstance;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private T singletonInstance;
|
||||
|
||||
private @Nullable T earlySingletonInstance;
|
||||
|
||||
@@ -146,7 +147,6 @@ public abstract class AbstractFactoryBean<T>
|
||||
* @see #getEarlySingletonInterfaces()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
public final T getObject() throws Exception {
|
||||
if (isSingleton()) {
|
||||
return (this.initialized ? this.singletonInstance : getEarlySingletonInstance());
|
||||
|
||||
@@ -224,7 +224,6 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
|
||||
StringValueResolver valueResolver) {
|
||||
|
||||
|
||||
@@ -89,13 +89,15 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
|
||||
|
||||
private @Nullable BeanWrapper targetBeanWrapper;
|
||||
|
||||
private @Nullable String targetBeanName;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private String targetBeanName;
|
||||
|
||||
private @Nullable String propertyPath;
|
||||
|
||||
private @Nullable Class<?> resultType;
|
||||
|
||||
private @Nullable String beanName;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private String beanName;
|
||||
|
||||
private @Nullable BeanFactory beanFactory;
|
||||
|
||||
@@ -156,7 +158,6 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
|
||||
|
||||
@@ -696,7 +696,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
|
||||
XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(
|
||||
new DescriptiveResource("Groovy"));
|
||||
|
||||
@@ -131,7 +131,7 @@ class ConstructorResolver {
|
||||
* or {@code null} if none (-> use constructor argument values from bean definition)
|
||||
* @return a BeanWrapper for the new instance
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd,
|
||||
Constructor<?> @Nullable [] chosenCtors, @Nullable Object @Nullable [] explicitArgs) {
|
||||
|
||||
@@ -393,7 +393,7 @@ class ConstructorResolver {
|
||||
* method, or {@code null} if none (-> use constructor argument values from bean definition)
|
||||
* @return a BeanWrapper for the new instance
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public BeanWrapper instantiateUsingFactoryMethod(
|
||||
String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] explicitArgs) {
|
||||
|
||||
|
||||
@@ -1499,7 +1499,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
return doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public @Nullable Object doResolveDependency(DependencyDescriptor descriptor, @Nullable String beanName,
|
||||
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
* with, if necessary
|
||||
* @return the registered singleton object
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan
|
||||
* Match the given dependency type with its generic type information against the given
|
||||
* candidate bean definition.
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
protected boolean checkGenericTypeMatch(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
|
||||
ResolvableType dependencyType = descriptor.getResolvableType();
|
||||
if (dependencyType.getType() instanceof Class) {
|
||||
|
||||
@@ -145,7 +145,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
|
||||
public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner,
|
||||
@Nullable Object factoryBean, Method factoryMethod, @Nullable Object... args) {
|
||||
|
||||
|
||||
@@ -407,7 +407,6 @@ public class BeanDefinitionParserDelegate {
|
||||
* if there were errors during parse. Errors are reported to the
|
||||
* {@link org.springframework.beans.factory.parsing.ProblemReporter}.
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
public @Nullable BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable BeanDefinition containingBean) {
|
||||
String id = ele.getAttribute(ID_ATTRIBUTE);
|
||||
String nameAttr = ele.getAttribute(NAME_ATTRIBUTE);
|
||||
@@ -457,7 +456,8 @@ public class BeanDefinitionParserDelegate {
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
error(ex.getMessage(), ele);
|
||||
String message = ex.getMessage();
|
||||
error(message == null ? "" : message, ele);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user