Skip to content

Commit 1b563f8

Browse files
committed
Refine null-safety in more modules
This commit refines the null-safety in: - spring-jdbc - spring-r2dbc - spring-orm - spring-beans - spring-aop See gh-32475
1 parent dea31dd commit 1b563f8

File tree

40 files changed

+69
-17
lines changed

40 files changed

+69
-17
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
2323
import org.springframework.beans.factory.aot.BeanRegistrationCode;
2424
import org.springframework.beans.factory.support.RegisteredBean;
25+
import org.springframework.lang.Nullable;
2526
import org.springframework.util.ClassUtils;
2627

2728
/**
@@ -38,6 +39,7 @@ class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotP
3839

3940

4041
@Override
42+
@Nullable
4143
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
4244
if (aspectjPresent) {
4345
Class<?> beanClass = registeredBean.getBeanClass();

spring-aop/src/main/java/org/springframework/aop/config/SpringConfiguredBeanDefinitionParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.beans.factory.support.RootBeanDefinition;
2424
import org.springframework.beans.factory.xml.BeanDefinitionParser;
2525
import org.springframework.beans.factory.xml.ParserContext;
26+
import org.springframework.lang.Nullable;
2627

2728
/**
2829
* {@link BeanDefinitionParser} responsible for parsing the
@@ -51,6 +52,7 @@ class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser {
5152

5253

5354
@Override
55+
@Nullable
5456
public BeanDefinition parse(Element element, ParserContext parserContext) {
5557
if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
5658
RootBeanDefinition def = new RootBeanDefinition();

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ public Object getEarlyBeanReference(Object bean, String beanName) {
270270
}
271271

272272
@Override
273+
@Nullable
273274
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
274275
Object cacheKey = getCacheKey(beanClass, beanName);
275276

@@ -311,6 +312,7 @@ public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, Str
311312
* @see #getAdvicesAndAdvisorsForBean
312313
*/
313314
@Override
315+
@Nullable
314316
public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) {
315317
if (bean != null) {
316318
Object cacheKey = getCacheKey(bean.getClass(), beanName);

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void setBeanNames(String... beanNames) {
8181
* @see #setBeanNames(String...)
8282
*/
8383
@Override
84+
@Nullable
8485
protected TargetSource getCustomTargetSource(Class<?> beanClass, String beanName) {
8586
return (isSupportedBeanName(beanClass, beanName) ?
8687
super.getCustomTargetSource(beanClass, beanName) : null);

spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
5353

5454

5555
@Override
56+
@Nullable
5657
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
5758
Class<?> beanClass = registeredBean.getBeanClass();
5859
if (beanClass.equals(ScopedProxyFactoryBean.class)) {

spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public void setBeanFactory(BeanFactory beanFactory) {
117117

118118

119119
@Override
120+
@Nullable
120121
public Object getObject() {
121122
if (this.proxy == null) {
122123
throw new FactoryBeanNotInitializedException();
@@ -125,6 +126,7 @@ public Object getObject() {
125126
}
126127

127128
@Override
129+
@Nullable
128130
public Class<?> getObjectType() {
129131
if (this.proxy != null) {
130132
return this.proxy.getClass();

spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public BeanInstantiationException(Class<?> beanClass, String msg, @Nullable Thro
6969
* @param cause the root cause
7070
* @since 4.3
7171
*/
72-
public BeanInstantiationException(Constructor<?> constructor, String msg, @Nullable Throwable cause) {
72+
public BeanInstantiationException(Constructor<?> constructor, @Nullable String msg, @Nullable Throwable cause) {
7373
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
7474
this.beanClass = constructor.getDeclaringClass();
7575
this.constructor = constructor;
@@ -84,7 +84,7 @@ public BeanInstantiationException(Constructor<?> constructor, String msg, @Nulla
8484
* @param cause the root cause
8585
* @since 4.3
8686
*/
87-
public BeanInstantiationException(Method constructingMethod, String msg, @Nullable Throwable cause) {
87+
public BeanInstantiationException(Method constructingMethod, @Nullable String msg, @Nullable Throwable cause) {
8888
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
8989
this.beanClass = constructingMethod.getReturnType();
9090
this.constructor = null;

spring-beans/src/main/java/org/springframework/beans/MethodInvocationException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.beans.PropertyChangeEvent;
2020

21+
import org.springframework.lang.Nullable;
22+
2123
/**
2224
* Thrown when a bean property getter or setter method throws an exception,
2325
* analogous to an InvocationTargetException.
@@ -38,7 +40,7 @@ public class MethodInvocationException extends PropertyAccessException {
3840
* @param propertyChangeEvent the PropertyChangeEvent that resulted in an exception
3941
* @param cause the Throwable raised by the invoked method
4042
*/
41-
public MethodInvocationException(PropertyChangeEvent propertyChangeEvent, Throwable cause) {
43+
public MethodInvocationException(PropertyChangeEvent propertyChangeEvent, @Nullable Throwable cause) {
4244
super(propertyChangeEvent, "Property '" + propertyChangeEvent.getPropertyName() + "' threw exception", cause);
4345
}
4446

spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public BeanCreationException(String beanName, String msg, Throwable cause) {
9494
* @param beanName the name of the bean requested
9595
* @param msg the detail message
9696
*/
97-
public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, String msg) {
97+
public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, @Nullable String msg) {
9898
super("Error creating bean with name '" + beanName + "'" +
9999
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
100100
this.resourceDescription = resourceDescription;
@@ -110,7 +110,7 @@ public BeanCreationException(@Nullable String resourceDescription, @Nullable Str
110110
* @param msg the detail message
111111
* @param cause the root cause
112112
*/
113-
public BeanCreationException(@Nullable String resourceDescription, String beanName, String msg, Throwable cause) {
113+
public BeanCreationException(@Nullable String resourceDescription, String beanName, @Nullable String msg, Throwable cause) {
114114
this(resourceDescription, beanName, msg);
115115
initCause(cause);
116116
}

spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException {
4444
* @param msg the detail message
4545
*/
4646
public UnsatisfiedDependencyException(
47-
@Nullable String resourceDescription, @Nullable String beanName, String propertyName, String msg) {
47+
@Nullable String resourceDescription, @Nullable String beanName, String propertyName, @Nullable String msg) {
4848

4949
super(resourceDescription, beanName,
5050
"Unsatisfied dependency expressed through bean property '" + propertyName + "'" +
@@ -75,7 +75,7 @@ public UnsatisfiedDependencyException(
7575
* @since 4.3
7676
*/
7777
public UnsatisfiedDependencyException(
78-
@Nullable String resourceDescription, @Nullable String beanName, @Nullable InjectionPoint injectionPoint, String msg) {
78+
@Nullable String resourceDescription, @Nullable String beanName, @Nullable InjectionPoint injectionPoint, @Nullable String msg) {
7979

8080
super(resourceDescription, beanName,
8181
"Unsatisfied dependency expressed through " + injectionPoint +

0 commit comments

Comments
 (0)