@@ -268,8 +268,8 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
268268 */
269269 public void setBeanFactory (BeanFactory beanFactory ) {
270270 this .beanFactory = beanFactory ;
271- if (beanFactory instanceof ConfigurableListableBeanFactory ) {
272- this .resolver = (( ConfigurableListableBeanFactory ) beanFactory ) .getBeanExpressionResolver ();
271+ if (beanFactory instanceof ConfigurableListableBeanFactory clbf ) {
272+ this .resolver = clbf .getBeanExpressionResolver ();
273273 this .expressionContext = new BeanExpressionContext ((ConfigurableListableBeanFactory ) beanFactory ,
274274 this .listenerScope );
275275 }
@@ -295,9 +295,9 @@ public void afterPropertiesSet() throws Exception {
295295 public void afterSingletonsInstantiated () {
296296 this .registrar .setBeanFactory (this .beanFactory );
297297
298- if (this .beanFactory instanceof ListableBeanFactory ) {
298+ if (this .beanFactory instanceof ListableBeanFactory lbf ) {
299299 Map <String , KafkaListenerConfigurer > instances =
300- (( ListableBeanFactory ) this . beanFactory ) .getBeansOfType (KafkaListenerConfigurer .class );
300+ lbf .getBeansOfType (KafkaListenerConfigurer .class );
301301 for (KafkaListenerConfigurer configurer : instances .values ()) {
302302 configurer .configureKafkaListeners (this .registrar );
303303 }
@@ -342,7 +342,7 @@ private void buildEnhancer() {
342342 List <AnnotationEnhancer > enhancers = enhancersMap .values ()
343343 .stream ()
344344 .sorted (new OrderComparator ())
345- .collect ( Collectors . toList () );
345+ .toList ();
346346 this .enhancer = (attrs , element ) -> {
347347 Map <String , Object > newAttrs = attrs ;
348348 for (AnnotationEnhancer enh : enhancers ) {
@@ -364,7 +364,7 @@ public Object postProcessAfterInitialization(final Object bean, final String bea
364364 if (!this .nonAnnotatedClasses .contains (bean .getClass ())) {
365365 Class <?> targetClass = AopUtils .getTargetClass (bean );
366366 Collection <KafkaListener > classLevelListeners = findListenerAnnotations (targetClass );
367- final boolean hasClassLevelListeners = classLevelListeners .size () > 0 ;
367+ final boolean hasClassLevelListeners = ! classLevelListeners .isEmpty () ;
368368 final List <Method > multiMethods = new ArrayList <>();
369369 Map <Method , Set <KafkaListener >> annotatedMethods = MethodIntrospector .selectMethods (targetClass ,
370370 (MethodIntrospector .MetadataLookup <Set <KafkaListener >>) method -> {
@@ -432,7 +432,7 @@ private Set<KafkaListener> findListenerAnnotations(Method method) {
432432 if (anns != null ) {
433433 listeners .addAll (Arrays .stream (anns .value ())
434434 .map (anno -> enhance (method , anno ))
435- .collect ( Collectors . toList () ));
435+ .toList ());
436436 }
437437 return listeners ;
438438 }
@@ -500,7 +500,7 @@ private boolean processMainAndRetryListeners(KafkaListener kafkaListener, Object
500500 retryableCandidates = Arrays .stream (tps )
501501 .map (tp -> tp .getTopic ())
502502 .distinct ()
503- .collect ( Collectors . toList () )
503+ .toList ()
504504 .toArray (new String [0 ]);
505505 }
506506
@@ -541,12 +541,11 @@ private RetryTopicConfigurer getRetryTopicConfigurer() {
541541 }
542542
543543 private RetryTopicConfigurer createDefaultConfigurer () {
544- if (this .applicationContext instanceof GenericApplicationContext ) {
545- GenericApplicationContext gac = (GenericApplicationContext ) this .applicationContext ;
544+ if (this .applicationContext instanceof GenericApplicationContext gac ) {
546545 gac .registerBean (
547546 RetryTopicBeanNames .DEFAULT_RETRY_TOPIC_CONFIG_SUPPORT_BEAN_NAME ,
548547 RetryTopicConfigurationSupport .class ,
549- () -> new RetryTopicConfigurationSupport () );
548+ RetryTopicConfigurationSupport :: new );
550549 RetryTopicConfigurationSupport rtcs = this .applicationContext .getBean (
551550 RetryTopicBeanNames .DEFAULT_RETRY_TOPIC_CONFIG_SUPPORT_BEAN_NAME ,
552551 RetryTopicConfigurationSupport .class );
@@ -638,8 +637,8 @@ private void processKafkaListenerAnnotation(MethodKafkaListenerEndpoint<?, ?> en
638637 String group = kafkaListener .containerGroup ();
639638 if (StringUtils .hasText (group )) {
640639 Object resolvedGroup = resolveExpression (group );
641- if (resolvedGroup instanceof String ) {
642- endpoint .setGroup (( String ) resolvedGroup );
640+ if (resolvedGroup instanceof String str ) {
641+ endpoint .setGroup (str );
643642 }
644643 }
645644 String concurrency = kafkaListener .concurrency ();
@@ -663,8 +662,8 @@ private void processKafkaListenerAnnotation(MethodKafkaListenerEndpoint<?, ?> en
663662
664663 private void resolveErrorHandler (MethodKafkaListenerEndpoint <?, ?> endpoint , KafkaListener kafkaListener ) {
665664 Object errorHandler = resolveExpression (kafkaListener .errorHandler ());
666- if (errorHandler instanceof KafkaListenerErrorHandler ) {
667- endpoint .setErrorHandler (( KafkaListenerErrorHandler ) errorHandler );
665+ if (errorHandler instanceof KafkaListenerErrorHandler kleh ) {
666+ endpoint .setErrorHandler (kleh );
668667 }
669668 else {
670669 String errorHandlerBeanName = resolveExpressionAsString (kafkaListener .errorHandler (), "errorHandler" );
@@ -677,8 +676,8 @@ private void resolveErrorHandler(MethodKafkaListenerEndpoint<?, ?> endpoint, Kaf
677676
678677 private void resolveContentTypeConverter (MethodKafkaListenerEndpoint <?, ?> endpoint , KafkaListener kafkaListener ) {
679678 Object converter = resolveExpression (kafkaListener .contentTypeConverter ());
680- if (converter instanceof SmartMessageConverter ) {
681- endpoint .setMessagingConverter (( SmartMessageConverter ) converter );
679+ if (converter instanceof SmartMessageConverter smc ) {
680+ endpoint .setMessagingConverter (smc );
682681 }
683682 else {
684683 String converterBeanName = resolveExpressionAsString (kafkaListener .contentTypeConverter (),
@@ -693,8 +692,8 @@ private void resolveContentTypeConverter(MethodKafkaListenerEndpoint<?, ?> endpo
693692 @ SuppressWarnings ({ "rawtypes" , UNCHECKED })
694693 private void resolveFilter (MethodKafkaListenerEndpoint <?, ?> endpoint , KafkaListener kafkaListener ) {
695694 Object filter = resolveExpression (kafkaListener .filter ());
696- if (filter instanceof RecordFilterStrategy ) {
697- endpoint .setRecordFilterStrategy (( RecordFilterStrategy ) filter );
695+ if (filter instanceof RecordFilterStrategy rfs ) {
696+ endpoint .setRecordFilterStrategy (rfs );
698697 }
699698 else {
700699 String filterBeanName = resolveExpressionAsString (kafkaListener .filter (), "filter" );
@@ -757,14 +756,14 @@ private void resolveKafkaProperties(MethodKafkaListenerEndpoint<?, ?> endpoint,
757756 if (value instanceof String ) {
758757 loadProperty (properties , property , value );
759758 }
760- else if (value instanceof String []) {
761- for (String prop : ( String []) value ) {
759+ else if (value instanceof String [] strArr ) {
760+ for (String prop : strArr ) {
762761 loadProperty (properties , prop , prop );
763762 }
764763 }
765764 else if (value instanceof Collection ) {
766765 Collection <?> values = (Collection <?>) value ;
767- if (values .size () > 0 && values .iterator ().next () instanceof String ) {
766+ if (! values .isEmpty () && values .iterator ().next () instanceof String ) {
768767 for (String prop : (Collection <String >) value ) {
769768 loadProperty (properties , prop , prop );
770769 }
@@ -836,11 +835,11 @@ private Pattern resolvePattern(KafkaListener kafkaListener) {
836835 String text = kafkaListener .topicPattern ();
837836 if (StringUtils .hasText (text )) {
838837 Object resolved = resolveExpression (text );
839- if (resolved instanceof Pattern ) {
840- pattern = ( Pattern ) resolved ;
838+ if (resolved instanceof Pattern pat ) {
839+ pattern = pat ;
841840 }
842- else if (resolved instanceof String ) {
843- pattern = Pattern .compile (( String ) resolved );
841+ else if (resolved instanceof String str ) {
842+ pattern = Pattern .compile (str );
844843 }
845844 else if (resolved != null ) {
846845 throw new IllegalStateException (
@@ -877,20 +876,20 @@ private List<TopicPartitionOffset> resolveTopicPartitionsList(TopicPartition top
877876 resolveInitialOffset (topic , partitionOffset ), isRelative (topic , partitionOffset ), true );
878877 }
879878 }
880- Assert .isTrue (result .size () > 0 , () -> "At least one partition required for " + topic );
879+ Assert .isTrue (! result .isEmpty () , () -> "At least one partition required for " + topic );
881880 return result ;
882881 }
883882
884883 private Long resolveInitialOffset (Object topic , PartitionOffset partitionOffset ) {
885884 Object initialOffsetValue = resolveExpression (partitionOffset .initialOffset ());
886885 Long initialOffset ;
887- if (initialOffsetValue instanceof String ) {
888- Assert .state (StringUtils .hasText (( String ) initialOffsetValue ),
886+ if (initialOffsetValue instanceof String str ) {
887+ Assert .state (StringUtils .hasText (str ),
889888 () -> "'initialOffset' in @PartitionOffset for topic '" + topic + "' cannot be empty" );
890- initialOffset = Long .valueOf (( String ) initialOffsetValue );
889+ initialOffset = Long .valueOf (str );
891890 }
892- else if (initialOffsetValue instanceof Long ) {
893- initialOffset = ( Long ) initialOffsetValue ;
891+ else if (initialOffsetValue instanceof Long lng ) {
892+ initialOffset = lng ;
894893 }
895894 else {
896895 throw new IllegalArgumentException (String .format (
@@ -903,11 +902,11 @@ else if (initialOffsetValue instanceof Long) {
903902 private boolean isRelative (Object topic , PartitionOffset partitionOffset ) {
904903 Object relativeToCurrentValue = resolveExpression (partitionOffset .relativeToCurrent ());
905904 Boolean relativeToCurrent ;
906- if (relativeToCurrentValue instanceof String ) {
907- relativeToCurrent = Boolean .valueOf (( String ) relativeToCurrentValue );
905+ if (relativeToCurrentValue instanceof String str ) {
906+ relativeToCurrent = Boolean .valueOf (str );
908907 }
909- else if (relativeToCurrentValue instanceof Boolean ) {
910- relativeToCurrent = ( Boolean ) relativeToCurrentValue ;
908+ else if (relativeToCurrentValue instanceof Boolean bool ) {
909+ relativeToCurrent = bool ;
911910 }
912911 else {
913912 throw new IllegalArgumentException (String .format (
@@ -919,13 +918,13 @@ else if (relativeToCurrentValue instanceof Boolean) {
919918
920919 @ SuppressWarnings (UNCHECKED )
921920 private void resolveAsString (Object resolvedValue , List <String > result ) {
922- if (resolvedValue instanceof String []) {
923- for (Object object : ( String []) resolvedValue ) {
921+ if (resolvedValue instanceof String [] strArr ) {
922+ for (Object object : strArr ) {
924923 resolveAsString (object , result );
925924 }
926925 }
927- else if (resolvedValue instanceof String ) {
928- result .add (( String ) resolvedValue );
926+ else if (resolvedValue instanceof String str ) {
927+ result .add (str );
929928 }
930929 else if (resolvedValue instanceof Iterable ) {
931930 for (Object object : (Iterable <Object >) resolvedValue ) {
@@ -942,17 +941,17 @@ else if (resolvedValue instanceof Iterable) {
942941 private void resolvePartitionAsInteger (String topic , Object resolvedValue ,
943942 List <TopicPartitionOffset > result , @ Nullable Long offset , boolean isRelative , boolean checkDups ) {
944943
945- if (resolvedValue instanceof String []) {
946- for (Object object : ( String []) resolvedValue ) {
944+ if (resolvedValue instanceof String [] strArr ) {
945+ for (Object object : strArr ) {
947946 resolvePartitionAsInteger (topic , object , result , offset , isRelative , checkDups );
948947 }
949948 }
950- else if (resolvedValue instanceof String ) {
951- Assert .state (StringUtils .hasText (( String ) resolvedValue ),
949+ else if (resolvedValue instanceof String str ) {
950+ Assert .state (StringUtils .hasText (str ),
952951 () -> "partition in @TopicPartition for topic '" + topic + "' cannot be empty" );
953- List <TopicPartitionOffset > collected = parsePartitions (( String ) resolvedValue )
952+ List <TopicPartitionOffset > collected = parsePartitions (str )
954953 .map (part -> new TopicPartitionOffset (topic , part , offset , isRelative ))
955- .collect ( Collectors . toList () );
954+ .toList ();
956955 if (checkDups ) {
957956 collected .forEach (tpo -> {
958957 Assert .state (!result .contains (tpo ), () ->
@@ -962,13 +961,13 @@ else if (resolvedValue instanceof String) {
962961 }
963962 result .addAll (collected );
964963 }
965- else if (resolvedValue instanceof Integer []) {
966- for (Integer partition : ( Integer []) resolvedValue ) {
964+ else if (resolvedValue instanceof Integer [] intArr ) {
965+ for (Integer partition : intArr ) {
967966 result .add (new TopicPartitionOffset (topic , partition ));
968967 }
969968 }
970- else if (resolvedValue instanceof Integer ) {
971- result .add (new TopicPartitionOffset (topic , ( Integer ) resolvedValue ));
969+ else if (resolvedValue instanceof Integer intgr ) {
970+ result .add (new TopicPartitionOffset (topic , intgr ));
972971 }
973972 else if (resolvedValue instanceof Iterable ) {
974973 for (Object object : (Iterable <Object >) resolvedValue ) {
@@ -983,8 +982,8 @@ else if (resolvedValue instanceof Iterable) {
983982
984983 private String resolveExpressionAsString (String value , String attribute ) {
985984 Object resolved = resolveExpression (value );
986- if (resolved instanceof String ) {
987- return ( String ) resolved ;
985+ if (resolved instanceof String str ) {
986+ return str ;
988987 }
989988 else if (resolved != null ) {
990989 throw new IllegalStateException (THE_LEFT + attribute + "] must resolve to a String. "
@@ -996,13 +995,13 @@ else if (resolved != null) {
996995 @ Nullable
997996 private byte [] resolveExpressionAsBytes (String value , String attribute ) {
998997 Object resolved = resolveExpression (value );
999- if (resolved instanceof String ) {
1000- if (StringUtils .hasText (( CharSequence ) resolved )) {
1001- return (( String ) resolved ) .getBytes (this .charset );
998+ if (resolved instanceof String str ) {
999+ if (StringUtils .hasText (str )) {
1000+ return str .getBytes (this .charset );
10021001 }
10031002 }
1004- else if (resolved instanceof byte []) {
1005- return ( byte []) resolved ;
1003+ else if (resolved instanceof byte [] bytes ) {
1004+ return bytes ;
10061005 }
10071006 else if (resolved != null ) {
10081007 throw new IllegalStateException (THE_LEFT + attribute + "] must resolve to a String or byte[]. "
@@ -1014,11 +1013,11 @@ else if (resolved != null) {
10141013 private Integer resolveExpressionAsInteger (String value , String attribute ) {
10151014 Object resolved = resolveExpression (value );
10161015 Integer result = null ;
1017- if (resolved instanceof String ) {
1018- result = Integer .parseInt (( String ) resolved );
1016+ if (resolved instanceof String str ) {
1017+ result = Integer .parseInt (str );
10191018 }
1020- else if (resolved instanceof Number ) {
1021- result = (( Number ) resolved ) .intValue ();
1019+ else if (resolved instanceof Number nbr ) {
1020+ result = nbr .intValue ();
10221021 }
10231022 else if (resolved != null ) {
10241023 throw new IllegalStateException (
@@ -1031,11 +1030,11 @@ else if (resolved != null) {
10311030 private Boolean resolveExpressionAsBoolean (String value , String attribute ) {
10321031 Object resolved = resolveExpression (value );
10331032 Boolean result = null ;
1034- if (resolved instanceof Boolean ) {
1035- result = ( Boolean ) resolved ;
1033+ if (resolved instanceof Boolean bool ) {
1034+ result = bool ;
10361035 }
1037- else if (resolved instanceof String ) {
1038- result = Boolean .parseBoolean (( String ) resolved );
1036+ else if (resolved instanceof String str ) {
1037+ result = Boolean .parseBoolean (str );
10391038 }
10401039 else if (resolved != null ) {
10411040 throw new IllegalStateException (
@@ -1056,8 +1055,8 @@ private Object resolveExpression(String value) {
10561055 * @see ConfigurableBeanFactory#resolveEmbeddedValue
10571056 */
10581057 private String resolve (String value ) {
1059- if (this .beanFactory != null && this . beanFactory instanceof ConfigurableBeanFactory ) {
1060- return (( ConfigurableBeanFactory ) this . beanFactory ) .resolveEmbeddedValue (value );
1058+ if (this .beanFactory instanceof ConfigurableBeanFactory cbf ) {
1059+ return cbf .resolveEmbeddedValue (value );
10611060 }
10621061 return value ;
10631062 }
@@ -1078,9 +1077,8 @@ private void addFormatters(FormatterRegistry registry) {
10781077 }
10791078
10801079 private <T > Collection <T > getBeansOfType (Class <T > type ) {
1081- if (KafkaListenerAnnotationBeanPostProcessor .this .beanFactory instanceof ListableBeanFactory ) {
1082- return ((ListableBeanFactory ) KafkaListenerAnnotationBeanPostProcessor .this .beanFactory )
1083- .getBeansOfType (type )
1080+ if (KafkaListenerAnnotationBeanPostProcessor .this .beanFactory instanceof ListableBeanFactory lbf ) {
1081+ return lbf .getBeansOfType (type )
10841082 .values ();
10851083 }
10861084 else {
@@ -1276,11 +1274,11 @@ else if (targetType.getType().equals(int.class) || targetType.getType().equals(I
12761274 return ByteBuffer .wrap (bytes ).getInt ();
12771275 }
12781276 else if (targetType .getType ().equals (short .class ) || targetType .getType ().equals (Short .class )) {
1279- Assert .state (bytes .length >= 2 , "At least 2 bytes needed to convert a byte[] to a short" );
1277+ Assert .state (bytes .length >= 2 , "At least 2 bytes needed to convert a byte[] to a short" ); // NOSONAR
12801278 return ByteBuffer .wrap (bytes ).getShort ();
12811279 }
12821280 else if (targetType .getType ().equals (byte .class ) || targetType .getType ().equals (Byte .class )) {
1283- Assert .state (bytes .length >= 1 , "At least 1 byte needed to convert a byte[] to a byte" );
1281+ Assert .state (bytes .length >= 1 , "At least 1 byte needed to convert a byte[] to a byte" ); // NOSONAR
12841282 return ByteBuffer .wrap (bytes ).get ();
12851283 }
12861284 return null ;
0 commit comments