@@ -135,7 +135,7 @@ public abstract class MessagingMessageListenerAdapter<K, V> implements ConsumerS
135135 * @param bean the bean.
136136 * @param method the method.
137137 */
138- public MessagingMessageListenerAdapter (Object bean , Method method ) {
138+ protected MessagingMessageListenerAdapter (Object bean , Method method ) {
139139 this .bean = bean ;
140140 this .inferredType = determineInferredType (method ); // NOSONAR = intentionally not final
141141 }
@@ -310,35 +310,35 @@ public void setSplitIterables(boolean splitIterables) {
310310
311311 @ Override
312312 public void registerSeekCallback (ConsumerSeekCallback callback ) {
313- if (this .bean instanceof ConsumerSeekAware ) {
314- (( ConsumerSeekAware ) this . bean ) .registerSeekCallback (callback );
313+ if (this .bean instanceof ConsumerSeekAware csa ) {
314+ csa .registerSeekCallback (callback );
315315 }
316316 }
317317
318318 @ Override
319319 public void onPartitionsAssigned (Map <TopicPartition , Long > assignments , ConsumerSeekCallback callback ) {
320- if (this .bean instanceof ConsumerSeekAware ) {
321- (( ConsumerSeekAware ) this . bean ) .onPartitionsAssigned (assignments , callback );
320+ if (this .bean instanceof ConsumerSeekAware csa ) {
321+ csa .onPartitionsAssigned (assignments , callback );
322322 }
323323 }
324324
325325 @ Override
326326 public void onPartitionsRevoked (Collection <TopicPartition > partitions ) {
327- if (this .bean instanceof ConsumerSeekAware ) {
328- (( ConsumerSeekAware ) this . bean ) .onPartitionsRevoked (partitions );
327+ if (this .bean instanceof ConsumerSeekAware csa ) {
328+ csa .onPartitionsRevoked (partitions );
329329 }
330330 }
331331
332332 @ Override
333333 public void onIdleContainer (Map <TopicPartition , Long > assignments , ConsumerSeekCallback callback ) {
334- if (this .bean instanceof ConsumerSeekAware ) {
335- (( ConsumerSeekAware ) this . bean ) .onIdleContainer (assignments , callback );
334+ if (this .bean instanceof ConsumerSeekAware csa ) {
335+ csa .onIdleContainer (assignments , callback );
336336 }
337337 }
338338
339- protected Message <?> toMessagingMessage (ConsumerRecord <K , V > record , @ Nullable Acknowledgment acknowledgment ,
339+ protected Message <?> toMessagingMessage (ConsumerRecord <K , V > cRecord , @ Nullable Acknowledgment acknowledgment ,
340340 Consumer <?, ?> consumer ) {
341- return getMessageConverter ().toMessage (record , acknowledgment , consumer , getType ());
341+ return getMessageConverter ().toMessage (cRecord , acknowledgment , consumer , getType ());
342342 }
343343
344344 /**
@@ -417,8 +417,8 @@ protected void handleResult(Object resultArg, Object request, Object source) {
417417 @ Nullable
418418 private String evaluateReplyTopic (Object request , Object source , Object result ) {
419419 String replyTo = null ;
420- if (result instanceof InvocationResult ) {
421- replyTo = evaluateTopic (request , source , result , (( InvocationResult ) result ) .getSendTo ());
420+ if (result instanceof InvocationResult invResult ) {
421+ replyTo = evaluateTopic (request , source , result , invResult .getSendTo ());
422422 }
423423 else if (this .replyTopicExpression != null ) {
424424 replyTo = evaluateTopic (request , source , result , this .replyTopicExpression );
@@ -492,7 +492,7 @@ else if (result instanceof Message) {
492492 }
493493 }
494494
495- private Message <?> checkHeaders (Object result , String topic , Object source ) { // NOSONAR (complexity)
495+ private Message <?> checkHeaders (Object result , String topic , @ Nullable Object source ) { // NOSONAR (complexity)
496496 Message <?> reply = (Message <?>) result ;
497497 MessageHeaders headers = reply .getHeaders ();
498498 boolean needsTopic = headers .get (KafkaHeaders .TOPIC ) == null ;
@@ -642,8 +642,8 @@ else if (methodParameter.hasParameterAnnotation(Header.class)) {
642642 allowedBatchParameters ++;
643643 }
644644 else {
645- if (parameterType instanceof ParameterizedType
646- && (( ParameterizedType ) parameterType ) .getRawType ().equals (Consumer .class )) {
645+ if (parameterType instanceof ParameterizedType paramType
646+ && paramType .getRawType ().equals (Consumer .class )) {
647647 allowedBatchParameters ++;
648648 }
649649 }
@@ -672,8 +672,7 @@ else if (methodParameter.hasParameterAnnotation(Header.class)) {
672672
673673 private Type extractGenericParameterTypFromMethodParameter (MethodParameter methodParameter ) {
674674 Type genericParameterType = methodParameter .getGenericParameterType ();
675- if (genericParameterType instanceof ParameterizedType ) {
676- ParameterizedType parameterizedType = (ParameterizedType ) genericParameterType ;
675+ if (genericParameterType instanceof ParameterizedType parameterizedType ) {
677676 if (parameterizedType .getRawType ().equals (Message .class )) {
678677 genericParameterType = ((ParameterizedType ) genericParameterType ).getActualTypeArguments ()[0 ];
679678 }
@@ -684,8 +683,8 @@ else if (parameterizedType.getRawType().equals(List.class)
684683 this .isConsumerRecordList = paramType .equals (ConsumerRecord .class )
685684 || (isSimpleListOfConsumerRecord (paramType )
686685 || isListOfConsumerRecordUpperBounded (paramType ));
687- boolean messageHasGeneric = paramType instanceof ParameterizedType
688- && (( ParameterizedType ) paramType ) .getRawType ().equals (Message .class );
686+ boolean messageHasGeneric = paramType instanceof ParameterizedType pType
687+ && pType .getRawType ().equals (Message .class );
689688 this .isMessageList = paramType .equals (Message .class ) || messageHasGeneric ;
690689 if (messageHasGeneric ) {
691690 genericParameterType = ((ParameterizedType ) paramType ).getActualTypeArguments ()[0 ];
@@ -699,26 +698,23 @@ else if (parameterizedType.getRawType().equals(List.class)
699698 }
700699
701700 private boolean isSimpleListOfConsumerRecord (Type paramType ) {
702- return paramType instanceof ParameterizedType
703- && ((ParameterizedType ) paramType ).getRawType ().equals (ConsumerRecord .class );
701+ return paramType instanceof ParameterizedType pType && pType .getRawType ().equals (ConsumerRecord .class );
704702 }
705703
706704 private boolean isListOfConsumerRecordUpperBounded (Type paramType ) {
707705 return isWildCardWithUpperBound (paramType )
708- && ((WildcardType ) paramType ).getUpperBounds ()[0 ] instanceof ParameterizedType
709- && ((ParameterizedType ) ((WildcardType ) paramType ).getUpperBounds ()[0 ])
710- .getRawType ().equals (ConsumerRecord .class );
706+ && ((WildcardType ) paramType ).getUpperBounds ()[0 ] instanceof ParameterizedType wildCardZero
707+ && wildCardZero .getRawType ().equals (ConsumerRecord .class );
711708 }
712709
713710 private boolean isWildCardWithUpperBound (Type paramType ) {
714- return paramType instanceof WildcardType
715- && (( WildcardType ) paramType ) .getUpperBounds () != null
716- && (( WildcardType ) paramType ) .getUpperBounds ().length > 0 ;
711+ return paramType instanceof WildcardType wcType
712+ && wcType .getUpperBounds () != null
713+ && wcType .getUpperBounds ().length > 0 ;
717714 }
718715
719716 private boolean isMessageWithNoTypeInfo (Type parameterType ) {
720- if (parameterType instanceof ParameterizedType ) {
721- ParameterizedType parameterizedType = (ParameterizedType ) parameterType ;
717+ if (parameterType instanceof ParameterizedType parameterizedType ) {
722718 Type rawType = parameterizedType .getRawType ();
723719 if (rawType .equals (Message .class )) {
724720 return parameterizedType .getActualTypeArguments ()[0 ] instanceof WildcardType ;
@@ -728,8 +724,7 @@ private boolean isMessageWithNoTypeInfo(Type parameterType) {
728724 }
729725
730726 private boolean parameterIsType (Type parameterType , Type type ) {
731- if (parameterType instanceof ParameterizedType ) {
732- ParameterizedType parameterizedType = (ParameterizedType ) parameterType ;
727+ if (parameterType instanceof ParameterizedType parameterizedType ) {
733728 Type rawType = parameterizedType .getRawType ();
734729 if (rawType .equals (type )) {
735730 return true ;
@@ -740,34 +735,12 @@ private boolean parameterIsType(Type parameterType, Type type) {
740735
741736 /**
742737 * Root object for reply expression evaluation.
738+ * @param request the request.
739+ * @param source the source.
740+ * @param result the result.
743741 * @since 2.0
744742 */
745- public static final class ReplyExpressionRoot {
746-
747- private final Object request ;
748-
749- private final Object source ;
750-
751- private final Object result ;
752-
753- public ReplyExpressionRoot (Object request , Object source , Object result ) {
754- this .request = request ;
755- this .source = source ;
756- this .result = result ;
757- }
758-
759- public Object getRequest () {
760- return this .request ;
761- }
762-
763- public Object getSource () {
764- return this .source ;
765- }
766-
767- public Object getResult () {
768- return this .result ;
769- }
770-
743+ public record ReplyExpressionRoot (Object request , Object source , Object result ) {
771744 }
772745
773746}
0 commit comments