Skip to content

Commit 7e8d325

Browse files
committed
GH-3425: Return modified map from AnnotationEnhancer (#3428)
Fixes: #3425 Implement fix for issue #3425 by modifying AnnotationEnhancer to return the updated map after processing. This change ensures that all annotation enhancements are properly reflected in the returned result. Modifying an existing test to verify this behavior. **Auto-cherry-pick to `3.2.x` & `3.1.x`**
1 parent 84653be commit 7e8d325

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
* @author Filip Halemba
140140
* @author Tomaz Fernandes
141141
* @author Wang Zhiyang
142+
* @author Sanghyeok An
143+
* @author Soby Chacko
142144
*
143145
* @see KafkaListener
144146
* @see KafkaListenerErrorHandler
@@ -351,7 +353,7 @@ private void buildEnhancer() {
351353
for (AnnotationEnhancer enh : enhancers) {
352354
newAttrs = enh.apply(newAttrs, element);
353355
}
354-
return attrs;
356+
return newAttrs;
355357
};
356358
}
357359
}

spring-kafka/src/test/java/org/springframework/kafka/annotation/AliasPropertiesTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2023 the original author or authors.
2+
* Copyright 2018-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import java.lang.annotation.Target;
2525
import java.lang.reflect.AnnotatedElement;
2626
import java.lang.reflect.Method;
27+
import java.util.HashMap;
2728
import java.util.Map;
2829
import java.util.concurrent.CountDownLatch;
2930
import java.util.concurrent.TimeUnit;
@@ -56,6 +57,7 @@
5657
/**
5758
* @author Gary Russell
5859
* @author Artem Bilan
60+
* @author Soby Chacko
5961
*
6062
* @since 2.2
6163
*
@@ -113,13 +115,15 @@ public static class Config {
113115

114116
@Bean
115117
public static AnnotationEnhancer mainEnhancer() {
118+
116119
return (attrs, element) -> {
117-
attrs.put("groupId", attrs.get("id") + "." + (element instanceof Class
120+
Map<String, Object> newAttrs = new HashMap<>(attrs);
121+
newAttrs.put("groupId", attrs.get("id") + "." + (element instanceof Class
118122
? ((Class<?>) element).getSimpleName()
119123
: ((Method) element).getDeclaringClass().getSimpleName()
120124
+ "." + ((Method) element).getName()));
121125
orderedCalledFirst.set(true);
122-
return attrs;
126+
return newAttrs;
123127
};
124128
}
125129

0 commit comments

Comments
 (0)