Skip to content

Commit ba5b219

Browse files
committed
GH-3425: Return modified map from AnnotationEnhancer
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.
1 parent 78d7724 commit ba5b219

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
* @author Tomaz Fernandes
143143
* @author Wang Zhiyang
144144
* @author Sanghyeok An
145+
* @author Soby Chacko
145146
*
146147
* @see KafkaListener
147148
* @see KafkaListenerErrorHandler
@@ -360,7 +361,7 @@ private void buildEnhancer() {
360361
for (AnnotationEnhancer enh : enhancers) {
361362
newAttrs = enh.apply(newAttrs, element);
362363
}
363-
return attrs;
364+
return newAttrs;
364365
};
365366
}
366367
}

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)