Nullability refinements and related polishing

See gh-32475
This commit is contained in:
Juergen Hoeller
2024-03-19 09:58:44 +01:00
parent cd7ba1835c
commit c531a8a705
58 changed files with 327 additions and 257 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1096,7 +1096,13 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
}
if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isSuspendingFunction(method)) {
return Mono.fromFuture(cache.retrieve(key, () -> ((Mono<?>) invokeOperation(invoker)).toFuture()));
return Mono.fromFuture(cache.retrieve(key, () -> {
Mono<?> mono = ((Mono<?>) invokeOperation(invoker));
if (mono == null) {
mono = Mono.empty();
}
return mono.toFuture();
}));
}
return NOT_HANDLED;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,12 +78,13 @@ public class CacheInterceptor extends CacheAspectSupport implements MethodInterc
}
}
/**
* Inner class to avoid a hard dependency on Kotlin at runtime.
*/
private static class KotlinDelegate {
public static Publisher<?> invokeSuspendingFunction(Method method, Object target, Object... args) {
public static Publisher<?> invokeSuspendingFunction(Method method, @Nullable Object target, Object... args) {
Continuation<?> continuation = (Continuation<?>) args[args.length - 1];
CoroutineContext coroutineContext = continuation.getContext().minusKey(Job.Key);
return CoroutinesUtils.invokeSuspendingFunction(coroutineContext, method, target, args);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -257,6 +257,7 @@ public abstract class AbstractAotProcessor<T> {
* @return this builder for method chaining
*/
public Builder groupId(String groupId) {
Assert.hasText(groupId, "'groupId' must not be empty");
this.groupId = groupId;
return this;
}
@@ -268,6 +269,7 @@ public abstract class AbstractAotProcessor<T> {
* @return this builder for method chaining
*/
public Builder artifactId(String artifactId) {
Assert.hasText(artifactId, "'artifactId' must not be empty");
this.artifactId = artifactId;
return this;
}
@@ -279,14 +281,12 @@ public abstract class AbstractAotProcessor<T> {
Assert.notNull(this.sourceOutput, "'sourceOutput' must not be null");
Assert.notNull(this.resourceOutput, "'resourceOutput' must not be null");
Assert.notNull(this.classOutput, "'classOutput' must not be null");
Assert.hasText(this.groupId, "'groupId' must not be null or empty");
Assert.hasText(this.artifactId, "'artifactId' must not be null or empty");
Assert.notNull(this.groupId, "'groupId' must not be null");
Assert.notNull(this.artifactId, "'artifactId' must not be null");
return new Settings(this.sourceOutput, this.resourceOutput, this.classOutput,
this.groupId, this.artifactId);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -318,8 +318,8 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
}
}
private void publishEvents(Object result) {
if (result.getClass().isArray()) {
private void publishEvents(@Nullable Object result) {
if (result != null && result.getClass().isArray()) {
Object[] events = ObjectUtils.toObjectArray(result);
for (Object event : events) {
publishEvent(event);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,18 +83,21 @@ public class MBeanProxyFactoryBean extends MBeanClientInterceptor
public void afterPropertiesSet() throws MBeanServerNotFoundException, MBeanInfoRetrievalException {
super.afterPropertiesSet();
Class<?> interfaceToUse;
if (this.proxyInterface == null) {
this.proxyInterface = getManagementInterface();
if (this.proxyInterface == null) {
interfaceToUse = getManagementInterface();
if (interfaceToUse == null) {
throw new IllegalArgumentException("Property 'proxyInterface' or 'managementInterface' is required");
}
this.proxyInterface = interfaceToUse;
}
else {
interfaceToUse = this.proxyInterface;
if (getManagementInterface() == null) {
setManagementInterface(this.proxyInterface);
setManagementInterface(interfaceToUse);
}
}
this.mbeanProxy = new ProxyFactory(this.proxyInterface, this).getProxy(this.beanClassLoader);
this.mbeanProxy = new ProxyFactory(interfaceToUse, this).getProxy(this.beanClassLoader);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1035,7 +1035,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
Class<?> constructorClass, String nestedPath, String name, @Nullable Object value) {
Object[] hints = null;
if (this.targetType.getSource() instanceof MethodParameter parameter) {
if (this.targetType != null && this.targetType.getSource() instanceof MethodParameter parameter) {
for (Annotation ann : parameter.getParameterAnnotations()) {
hints = ValidationAnnotationUtils.determineValidationHints(ann);
if (hints != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,8 +79,8 @@ import org.springframework.validation.method.ParameterValidationResult;
*/
public class MethodValidationInterceptor implements MethodInterceptor {
private static final boolean REACTOR_PRESENT =
ClassUtils.isPresent("reactor.core.publisher.Mono", MethodValidationInterceptor.class.getClassLoader());
private static final boolean reactorPresent = ClassUtils.isPresent(
"reactor.core.publisher.Mono", MethodValidationInterceptor.class.getClassLoader());
private final MethodValidationAdapter validationAdapter;
@@ -153,7 +153,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
Object[] arguments = invocation.getArguments();
Class<?>[] groups = determineValidationGroups(invocation);
if (REACTOR_PRESENT) {
if (reactorPresent) {
arguments = ReactorValidationHelper.insertAsyncValidation(
this.validationAdapter.getSpringValidatorAdapter(), this.adaptViolations,
target, method, arguments);