GH-110 - Switch to JSpecify for nullness analysis.

This commit is contained in:
Oliver Drotbohm
2025-02-14 15:39:01 +01:00
parent d3c31d46ed
commit e5021d0765
7 changed files with 96 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.plugin.core.config;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -58,8 +59,13 @@ public class PluginRegistriesBeanDefinitionRegistrar implements ImportBeanDefini
return;
}
@Nullable
Class<?>[] types = (Class<?>[]) annotationAttributes.get("value");
if (types == null) {
return;
}
for (Class<?> type : types) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(PluginRegistryFactoryBean.class);

View File

@@ -1,5 +1,5 @@
/**
* This package contains configuration support classes to ease registry configuration with Spring namespaces.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.plugin.core.config;

View File

@@ -2,5 +2,5 @@
* This package contains the core plugin API. It allows other modules implementing components that extend functionality
* defined by a plugin interface. Plugin clients can be equipped with plugin implementations.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.plugin.core;

View File

@@ -22,6 +22,8 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@@ -30,8 +32,6 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.plugin.core.OrderAwarePluginRegistry;
import org.springframework.plugin.core.Plugin;
import org.springframework.plugin.core.PluginRegistry;
@@ -46,7 +46,7 @@ public class PluginRegistryFactoryBean<T extends Plugin<S>, S>
private Collection<Class<?>> exclusions = Collections.emptySet();
private @Nullable Class<T> type;
private ListableBeanFactory factory;
private @Nullable ListableBeanFactory factory;
/**
* Configures the type of beans to be looked up.
@@ -103,6 +103,12 @@ public class PluginRegistryFactoryBean<T extends Plugin<S>, S>
throw new IllegalStateException("No plugin type configured!");
}
var factory = this.factory;
if (factory == null) {
throw new IllegalStateException("No ListableBeanFactory configured!");
}
Supplier<List<? extends T>> plugins = () -> factory.getBeanProvider(type, false)
.stream(Predicate.not(exclusions::contains))
.toList();

View File

@@ -2,5 +2,5 @@
* This package contains support classes to create bean lists or plugin registry instances out of beans implementing a
* certain interface.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.plugin.core.support;