Skip to content

fix: AnnotationEnhancer chain silently discards all modifications - #775

Open
lossend wants to merge 1 commit into
apache:masterfrom
lossend:fix/annotation-enhancer-return-newAttrs
Open

fix: AnnotationEnhancer chain silently discards all modifications#775
lossend wants to merge 1 commit into
apache:masterfrom
lossend:fix/annotation-enhancer-return-newAttrs

Conversation

@lossend

@lossend lossend commented Jun 15, 2026

Copy link
Copy Markdown

Fixes #776

Problem

In RocketMQMessageListenerBeanPostProcessor.buildEnhancer(), the lambda accumulates
enhanced annotation attributes into newAttrs across all registered AnnotationEnhancer
beans, but then returns the original attrs instead of newAttrs.

This means every AnnotationEnhancer bean is silently a no-op — its attribute
modifications are computed but thrown away.

Fix

Return newAttrs instead of attrs.

// before
return attrs;

// after
return newAttrs;

Root Cause

buildEnhancer() (line 178–184):

this.enhancer = (attrs, element) -> {
    Map<String, Object> newAttrs = attrs;
    for (AnnotationEnhancer enh : enhancers) {
        newAttrs = enh.apply(newAttrs, element);
    }
    return attrs;   // BUG: should be newAttrs
};

Impact

Any application that relies on AnnotationEnhancer to dynamically override @RocketMQMessageListener attributes (e.g. injecting topic/group from environment properties) will find their customizations have no effect.

…chain

The buildEnhancer lambda was accumulating enhanced attributes into newAttrs
across all AnnotationEnhancer beans, but then returned the original attrs —
making all enhancers silently no-op.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@RockteMQ-AI

Copy link
Copy Markdown

PR Review for #775: fix: AnnotationEnhancer chain silently discards all modifications

Summary

This PR modifies 1 file(s) with +1/-1 lines changed.

Changed Files

  • rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java

Observations

  • PR author: @lossend
  • Diff size: 897 characters
  • 2 additions, 2 deletions in diff

Next Steps

A detailed code-level review requires the code engine. This is a structural overview only.
Please verify correctness, thread safety, and backward compatibility manually.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Clear bug fix: the buildEnhancer() lambda was returning the original attrs instead of the enhanced newAttrs, silently discarding all AnnotationEnhancer modifications. One-line fix that corrects the return value.

LGTM.


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This is a clear one-line bug fix: the AnnotationEnhancer chain lambda accumulates modifications into newAttrs but then returns the original attrs, silently discarding all enhancer modifications.

Analysis:

  • The bug is in buildEnhancer() at line 183: return attrs; should be return newAttrs;
  • The fix is correct and minimal — exactly one line changed
  • No side effects: newAttrs is initialized from attrs and only modified by the enhancer chain
  • This is a real bug that makes AnnotationEnhancer beans completely non-functional

LGTM. Good catch on a subtle but impactful bug.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Critical bug fix — the AnnotationEnhancer chain was silently discarding all modifications. The loop correctly applies each enhancer to newAttrs, but then returns the original attrs instead of the modified newAttrs. This one-line fix ensures the accumulated enhancements are actually returned.

This is a clear correctness bug: any custom AnnotationEnhancer implementations would have had zero effect at runtime. Well spotted.

LGTM.


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Critical bug fix. The AnnotationEnhancer chain was silently discarding all modifications because the code returned the original attrs instead of the accumulated newAttrs after applying all enhancers. This one-line fix corrects the return value.

Findings

  • [Critical] Without this fix, all annotation enhancements are lost. This could cause subtle bugs where custom annotation attributes (e.g., custom consumer/producer configurations) are ignored.

Suggestions

The fix is correct and minimal. Consider adding a unit test that verifies the enhancer chain actually modifies the annotation attributes, to prevent regression.


Automated review by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: AnnotationEnhancer chain silently discards all modifications in RocketMQMessageListenerBeanPostProcessor

2 participants