Refine null-safety based on IDEA warnings

See gh-28797
This commit is contained in:
Sébastien Deleuze
2025-01-22 12:20:41 +01:00
parent 4189f8b477
commit 7f21443a1b
22 changed files with 61 additions and 47 deletions

View File

@@ -63,7 +63,7 @@ final class BeanMethod extends ConfigurationMethod {
return;
}
Map<String, Object> attributes =
Map<String, @Nullable Object> attributes =
getConfigurationClass().getMetadata().getAnnotationAttributes(Configuration.class.getName());
if (attributes != null && (Boolean) attributes.get("proxyBeanMethods") && !getMetadata().isOverridable()) {
// instance @Bean methods within @Configuration classes must be overridable to accommodate CGLIB

View File

@@ -220,7 +220,7 @@ final class ConfigurationClass {
@SuppressWarnings("NullAway") // Reflection
void validate(ProblemReporter problemReporter) {
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName());
Map<String, @Nullable Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName());
// A configuration class may not be final (CGLIB limitation) unless it declares proxyBeanMethods=false
if (attributes != null && (Boolean) attributes.get("proxyBeanMethods") && this.metadata.isFinal()) {

View File

@@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
@@ -309,7 +310,7 @@ class ConfigurationClassBeanDefinitionReader {
ccbd.setNonUniqueFactoryMethodName(ccbd.getFactoryMethodMetadata().getMethodName());
return true;
}
Map<String, Object> attributes =
Map<String, @Nullable Object> attributes =
configClass.getMetadata().getAnnotationAttributes(Configuration.class.getName());
if ((attributes != null && (Boolean) attributes.get("enforceUniqueMethods")) ||
!this.registry.isBeanDefinitionOverridable(beanName)) {

View File

@@ -16,6 +16,8 @@
package org.springframework.context.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.MultiValueMap;
@@ -33,7 +35,7 @@ class ProfileCondition implements Condition {
@Override
@SuppressWarnings("NullAway") // Reflection
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
MultiValueMap<String, @Nullable Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
if (attrs != null) {
for (Object value : attrs.get("value")) {
if (context.getEnvironment().matchesProfiles((String[]) value)) {

View File

@@ -139,7 +139,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
}
@Override
public org.springframework.jmx.export.metadata.ManagedOperationParameter[] getManagedOperationParameters(Method method)
public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters(Method method)
throws InvalidMetadataException {
List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations(
@@ -149,7 +149,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
}
@Override
public org.springframework.jmx.export.metadata.ManagedNotification[] getManagedNotifications(Class<?> clazz)
public org.springframework.jmx.export.metadata.@Nullable ManagedNotification[] getManagedNotifications(Class<?> clazz)
throws InvalidMetadataException {
List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations(

View File

@@ -18,6 +18,7 @@ package org.springframework.jmx.export.assembler;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Objects;
import javax.management.Descriptor;
import javax.management.MBeanParameterInfo;
@@ -259,7 +260,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
*/
@Override
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
ManagedOperationParameter[] params = obtainAttributeSource().getManagedOperationParameters(method);
@Nullable ManagedOperationParameter[] params = obtainAttributeSource().getManagedOperationParameters(method);
if (ObjectUtils.isEmpty(params)) {
return super.getOperationParameters(method, beanKey);
}
@@ -267,7 +268,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
MBeanParameterInfo[] parameterInfo = new MBeanParameterInfo[params.length];
Class<?>[] methodParameters = method.getParameterTypes();
for (int i = 0; i < params.length; i++) {
ManagedOperationParameter param = params[i];
ManagedOperationParameter param = Objects.requireNonNull(params[i]);
parameterInfo[i] =
new MBeanParameterInfo(param.getName(), methodParameters[i].getName(), param.getDescription());
}
@@ -280,14 +281,14 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
*/
@Override
protected ModelMBeanNotificationInfo[] getNotificationInfo(Object managedBean, String beanKey) {
ManagedNotification[] notificationAttributes =
@Nullable ManagedNotification[] notificationAttributes =
obtainAttributeSource().getManagedNotifications(getClassToExpose(managedBean));
ModelMBeanNotificationInfo[] notificationInfos =
new ModelMBeanNotificationInfo[notificationAttributes.length];
for (int i = 0; i < notificationAttributes.length; i++) {
ManagedNotification attribute = notificationAttributes[i];
notificationInfos[i] = JmxMetadataUtils.convertToModelMBeanNotificationInfo(attribute);
notificationInfos[i] = JmxMetadataUtils.convertToModelMBeanNotificationInfo(Objects.requireNonNull(attribute));
}
return notificationInfos;

View File

@@ -80,7 +80,7 @@ public interface JmxAttributeSource {
* @return the parameter information.
* @throws InvalidMetadataException in the case of invalid attributes.
*/
ManagedOperationParameter[] getManagedOperationParameters(Method method) throws InvalidMetadataException;
@Nullable ManagedOperationParameter[] getManagedOperationParameters(Method method) throws InvalidMetadataException;
/**
* Implementations should return an array of {@link ManagedNotification ManagedNotifications}
@@ -90,7 +90,7 @@ public interface JmxAttributeSource {
* @return the notification information
* @throws InvalidMetadataException in the case of invalid metadata
*/
ManagedNotification[] getManagedNotifications(Class<?> clazz) throws InvalidMetadataException;
@Nullable ManagedNotification[] getManagedNotifications(Class<?> clazz) throws InvalidMetadataException;

View File

@@ -162,7 +162,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
return getBean(requiredType);
}
@Override
public T getObject(Object... args) throws BeansException {
public T getObject(@Nullable Object... args) throws BeansException {
return getBean(requiredType, args);
}
@Override