3232import java .util .List ;
3333import java .util .Locale ;
3434import java .util .Map ;
35+ import java .util .Objects ;
3536import java .util .Properties ;
3637import java .util .Set ;
3738import java .util .concurrent .ConcurrentHashMap ;
@@ -190,8 +191,7 @@ public class KafkaListenerAnnotationBeanPostProcessor<K, V>
190191
191192 private final AtomicBoolean enhancerIsBuilt = new AtomicBoolean ();
192193
193- @ SuppressWarnings ("NullAway.Init" )
194- private KafkaListenerEndpointRegistry endpointRegistry ;
194+ private @ Nullable KafkaListenerEndpointRegistry endpointRegistry ;
195195
196196 private String defaultContainerFactoryBeanName = DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME ;
197197
@@ -207,8 +207,7 @@ public class KafkaListenerAnnotationBeanPostProcessor<K, V>
207207
208208 private Charset charset = StandardCharsets .UTF_8 ;
209209
210- @ SuppressWarnings ("NullAway.Init" )
211- private AnnotationEnhancer enhancer ;
210+ private @ Nullable AnnotationEnhancer enhancer ;
212211
213212 private @ Nullable RetryTopicConfigurer retryTopicConfigurer ;
214213
@@ -327,18 +326,14 @@ public void afterSingletonsInstantiated() {
327326
328327 if (this .registrar .getEndpointRegistry () == null ) {
329328 if (this .endpointRegistry == null ) {
330- Assert .state (this .beanFactory != null ,
331- "BeanFactory must be set to find endpoint registry by bean name" );
332329 this .endpointRegistry = this .beanFactory .getBean (
333330 KafkaListenerConfigUtils .KAFKA_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME ,
334331 KafkaListenerEndpointRegistry .class );
335332 }
336333 this .registrar .setEndpointRegistry (this .endpointRegistry );
337334 }
338335
339- if (this .defaultContainerFactoryBeanName != null ) {
340- this .registrar .setContainerFactoryBeanName (this .defaultContainerFactoryBeanName );
341- }
336+ this .registrar .setContainerFactoryBeanName (this .defaultContainerFactoryBeanName );
342337
343338 // Set the custom handler method factory once resolved by the configurer
344339 MessageHandlerMethodFactory handlerMethodFactory = this .registrar .getMessageHandlerMethodFactory ();
@@ -864,11 +859,9 @@ private TopicPartitionOffset[] resolveTopicPartitions(KafkaListener kafkaListene
864859 private String [] resolveTopics (KafkaListener kafkaListener ) {
865860 String [] topics = kafkaListener .topics ();
866861 List <String > result = new ArrayList <>();
867- if (topics .length > 0 ) {
868- for (String topic1 : topics ) {
869- Object topic = resolveExpression (topic1 );
870- resolveAsString (topic , result );
871- }
862+ for (String topic1 : topics ) {
863+ Object topic = resolveExpression (topic1 );
864+ resolveAsString (topic , result );
872865 }
873866 return result .toArray (new String [0 ]);
874867 }
@@ -954,9 +947,9 @@ else if (initialOffsetValue instanceof Long lng) {
954947
955948 private boolean isRelative (Object topic , PartitionOffset partitionOffset ) {
956949 Object relativeToCurrentValue = resolveExpression (partitionOffset .relativeToCurrent ());
957- Boolean relativeToCurrent ;
950+ boolean relativeToCurrent ;
958951 if (relativeToCurrentValue instanceof String str ) {
959- relativeToCurrent = Boolean .valueOf (str );
952+ relativeToCurrent = Boolean .parseBoolean (str );
960953 }
961954 else if (relativeToCurrentValue instanceof Boolean bool ) {
962955 relativeToCurrent = bool ;
@@ -1046,8 +1039,7 @@ else if (resolvedValue instanceof Integer intgr) {
10461039 }
10471040 }
10481041
1049- @ SuppressWarnings ("NullAway" ) // Overridden method does not define nullness
1050- private TopicPartitionOffset .SeekPosition resloveTopicPartitionOffsetSeekPosition (@ Nullable Object seekPosition ) {
1042+ private TopicPartitionOffset .@ Nullable SeekPosition resloveTopicPartitionOffsetSeekPosition (@ Nullable Object seekPosition ) {
10511043 TopicPartitionOffset .SeekPosition resloveTpoSp = null ;
10521044 if (seekPosition instanceof String seekPositionName ) {
10531045 String capitalLetterSeekPositionName = seekPositionName .trim ().toUpperCase (Locale .ROOT );
@@ -1087,8 +1079,7 @@ else if (resolved != null) {
10871079 return null ;
10881080 }
10891081
1090- @ SuppressWarnings ("NullAway" ) // Dataflow analysis limitation
1091- private byte [] resolveExpressionAsBytes (String value , String attribute ) {
1082+ private byte @ Nullable [] resolveExpressionAsBytes (String value , String attribute ) {
10921083 Object resolved = resolveExpression (value );
10931084 if (resolved instanceof String str ) {
10941085 if (StringUtils .hasText (str )) {
@@ -1277,7 +1268,7 @@ public String convert(byte[] source) {
12771268
12781269 static class ListenerScope implements Scope {
12791270
1280- private final Map <String , @ Nullable Object > listeners = new HashMap <>();
1271+ private final Map <String , Object > listeners = new HashMap <>();
12811272
12821273 ListenerScope () {
12831274 }
@@ -1290,16 +1281,15 @@ public void removeListener(String key) {
12901281 this .listeners .remove (key );
12911282 }
12921283
1293- @ SuppressWarnings ("NullAway" ) // Overridden method does not define nullness
12941284 @ Override
1295- public @ Nullable Object get (String name , ObjectFactory <?> objectFactory ) {
1285+ public Object get (String name , ObjectFactory <?> objectFactory ) {
1286+ Objects .requireNonNull (this .listeners .get (name ), "No listeners registered for " + name );
12961287 return this .listeners .get (name );
12971288 }
12981289
1299- @ SuppressWarnings ("NullAway" ) // Overridden method does not define nullness
13001290 @ Override
1301- public Object remove (String name ) {
1302- return null ;
1291+ public @ Nullable Object remove (String name ) {
1292+ return this . listeners . remove ( name ) ;
13031293 }
13041294
13051295 @ Override
@@ -1324,7 +1314,7 @@ public void registerDestructionCallback(String name, Runnable callback) {
13241314 * @since 2.7.2
13251315 *
13261316 */
1327- public interface AnnotationEnhancer extends BiFunction <Map <String , Object >, AnnotatedElement , Map <String , Object >> {
1317+ public interface AnnotationEnhancer extends BiFunction <Map <String , @ Nullable Object >, AnnotatedElement , Map <String , Object >> {
13281318
13291319 }
13301320
0 commit comments