Skip to content

Commit 42366b6

Browse files
committed
Add nullability annotations to module/spring-boot-pulsar
See gh-46587
1 parent 19ec929 commit 42366b6

File tree

7 files changed

+101
-79
lines changed

7 files changed

+101
-79
lines changed

module/spring-boot-pulsar/src/main/java/org/springframework/boot/pulsar/autoconfigure/PulsarConfiguration.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.pulsar.client.api.Schema;
2626
import org.apache.pulsar.common.naming.TopicDomain;
2727
import org.apache.pulsar.common.schema.SchemaType;
28+
import org.jspecify.annotations.Nullable;
2829

2930
import org.springframework.beans.factory.ObjectProvider;
3031
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -127,7 +128,8 @@ DefaultSchemaResolver pulsarSchemaResolver(ObjectProvider<SchemaResolverCustomiz
127128
return schemaResolver;
128129
}
129130

130-
private void addCustomSchemaMappings(DefaultSchemaResolver schemaResolver, List<TypeMapping> typeMappings) {
131+
private void addCustomSchemaMappings(DefaultSchemaResolver schemaResolver,
132+
@Nullable List<TypeMapping> typeMappings) {
131133
if (typeMappings != null) {
132134
typeMappings.forEach((typeMapping) -> addCustomSchemaMapping(schemaResolver, typeMapping));
133135
}
@@ -139,11 +141,17 @@ private void addCustomSchemaMapping(DefaultSchemaResolver schemaResolver, TypeMa
139141
Class<?> messageType = typeMapping.messageType();
140142
SchemaType schemaType = schemaInfo.schemaType();
141143
Class<?> messageKeyType = schemaInfo.messageKeyType();
142-
Schema<?> schema = schemaResolver.resolveSchema(schemaType, messageType, messageKeyType).orElseThrow();
144+
Schema<?> schema = getSchema(schemaResolver, schemaType, messageType, messageKeyType);
143145
schemaResolver.addCustomSchemaMapping(typeMapping.messageType(), schema);
144146
}
145147
}
146148

149+
@SuppressWarnings("NullAway") // Resolved.orElseThrow() doesn't return nullable
150+
private Schema<Object> getSchema(DefaultSchemaResolver schemaResolver, SchemaType schemaType, Class<?> messageType,
151+
@Nullable Class<?> messageKeyType) {
152+
return schemaResolver.resolveSchema(schemaType, messageType, messageKeyType).orElseThrow();
153+
}
154+
147155
@SuppressWarnings("unchecked")
148156
private void applySchemaResolverCustomizers(List<SchemaResolverCustomizer<?>> customizers,
149157
DefaultSchemaResolver schemaResolver) {

module/spring-boot-pulsar/src/main/java/org/springframework/boot/pulsar/autoconfigure/PulsarContainerFactoryCustomizers.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.util.LambdaSafe;
2426
import org.springframework.pulsar.config.PulsarContainerFactory;
2527
import org.springframework.pulsar.core.PulsarConsumerFactory;
@@ -34,7 +36,7 @@ class PulsarContainerFactoryCustomizers {
3436

3537
private final List<PulsarContainerFactoryCustomizer<?>> customizers;
3638

37-
PulsarContainerFactoryCustomizers(List<? extends PulsarContainerFactoryCustomizer<?>> customizers) {
39+
PulsarContainerFactoryCustomizers(@Nullable List<? extends PulsarContainerFactoryCustomizer<?>> customizers) {
3840
this.customizers = (customizers != null) ? new ArrayList<>(customizers) : Collections.emptyList();
3941
}
4042

0 commit comments

Comments
 (0)