Skip to content

Commit fe66062

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 9b386df commit fe66062

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
@@ -141,6 +141,8 @@
141141
* @author Filip Halemba
142142
* @author Tomaz Fernandes
143143
* @author Wang Zhiyang
144+
* @author Sanghyeok An
145+
* @author Soby Chacko
144146
*
145147
* @see KafkaListener
146148
* @see KafkaListenerErrorHandler
@@ -359,7 +361,7 @@ private void buildEnhancer() {
359361
for (AnnotationEnhancer enh : enhancers) {
360362
newAttrs = enh.apply(newAttrs, element);
361363
}
362-
return attrs;
364+
return newAttrs;
363365
};
364366
}
365367
}

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)