Perform NullAway build-time checks in more modules

This commit enables null-safety build-time checks in:
 - spring-jdbc
 - spring-r2dbc
 - spring-orm
 - spring-beans
 - spring-aop

See gh-32475
This commit is contained in:
Sébastien Deleuze
2024-03-26 09:55:41 +01:00
parent 3b4f8dbb8e
commit 5b660da52d
46 changed files with 78 additions and 12 deletions

View File

@@ -552,6 +552,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
* @param ex the exception thrown by the method execution (may be null)
* @return the empty array if there are no arguments
*/
@SuppressWarnings("NullAway")
protected Object[] argBinding(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
@Nullable Object returnValue, @Nullable Throwable ex) {

View File

@@ -77,7 +77,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
this.beanFactory = beanFactory;
this.name = name;
Class<?> resolvedType = type;
if (type == null) {
if (resolvedType == null) {
resolvedType = beanFactory.getType(name);
Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class");
}

View File

@@ -80,6 +80,7 @@ public class BeanFactoryAspectJAdvisorsBuilder {
* @return the list of {@link org.springframework.aop.Advisor} beans
* @see #isEligibleBean
*/
@SuppressWarnings("NullAway")
public List<Advisor> buildAspectJAdvisors() {
List<String> aspectNames = this.aspectBeanNames;

View File

@@ -195,6 +195,7 @@ final class InstantiationModelAwarePointcutAdvisorImpl
}
@Override
@SuppressWarnings("NullAway")
public boolean isBeforeAdvice() {
if (this.isBeforeAdvice == null) {
determineAdviceType();
@@ -203,6 +204,7 @@ final class InstantiationModelAwarePointcutAdvisorImpl
}
@Override
@SuppressWarnings("NullAway")
public boolean isAfterAdvice() {
if (this.isAfterAdvice == null) {
determineAdviceType();

View File

@@ -98,6 +98,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
*/
@Override
@Nullable
@SuppressWarnings("NullAway")
public Object invoke(final MethodInvocation invocation) throws Throwable {
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
final Method userMethod = BridgeMethodResolver.getMostSpecificMethod(invocation.getMethod(), targetClass);

View File

@@ -54,6 +54,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
@Override
@Nullable
@SuppressWarnings("NullAway")
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
Class<?> beanClass = registeredBean.getBeanClass();
if (beanClass.equals(ScopedProxyFactoryBean.class)) {

View File

@@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.lang.Contract;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -128,6 +129,7 @@ public abstract class ScopedProxyUtils {
* the target bean within a scoped proxy.
* @since 4.1.4
*/
@Contract("null -> false")
public static boolean isScopedTarget(@Nullable String beanName) {
return (beanName != null && beanName.startsWith(TARGET_NAME_PREFIX));
}

View File

@@ -43,6 +43,7 @@ import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.CoroutinesUtils;
import org.springframework.core.KotlinDetector;
import org.springframework.core.MethodIntrospector;
import org.springframework.lang.Contract;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -73,6 +74,7 @@ public abstract class AopUtils {
* @see #isJdkDynamicProxy
* @see #isCglibProxy
*/
@Contract("null -> false")
public static boolean isAopProxy(@Nullable Object object) {
return (object instanceof SpringProxy && (Proxy.isProxyClass(object.getClass()) ||
object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)));
@@ -86,6 +88,7 @@ public abstract class AopUtils {
* @param object the object to check
* @see java.lang.reflect.Proxy#isProxyClass
*/
@Contract("null -> false")
public static boolean isJdkDynamicProxy(@Nullable Object object) {
return (object instanceof SpringProxy && Proxy.isProxyClass(object.getClass()));
}
@@ -98,6 +101,7 @@ public abstract class AopUtils {
* @param object the object to check
* @see ClassUtils#isCglibProxy(Object)
*/
@Contract("null -> false")
public static boolean isCglibProxy(@Nullable Object object) {
return (object instanceof SpringProxy &&
object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR));

View File

@@ -87,6 +87,7 @@ public class AnnotationMatchingPointcut implements Pointcut {
* @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
* @see AnnotationMethodMatcher#AnnotationMethodMatcher(Class, boolean)
*/
@SuppressWarnings("NullAway")
public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,
@Nullable Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {

View File

@@ -66,6 +66,7 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
@Override
@SuppressWarnings("NullAway")
public synchronized Class<?> getTargetClass() {
if (this.targetObject == null) {
refresh();