Fix duplicate listener registration in ChunkOrientedStepBuilder - #5467
Open
benelog wants to merge 1 commit into
Open
Fix duplicate listener registration in ChunkOrientedStepBuilder#5467benelog wants to merge 1 commit into
benelog wants to merge 1 commit into
Conversation
An item reader/processor/writer that implements a StepListener sub-interface and also has a listener-annotated method was added to stepListeners twice: once as the raw object and once as a StepListenerFactoryBean proxy. Since the proxy resolves callbacks by interface as well as by annotation, every interface callback was invoked twice per item. Register through StepListenerFactoryBean only, as in 5.2.x: the factory already covers interface-only implementations and returns the delegate unchanged when no annotated methods are present. The added integration tests cover the failing case and the control case of an item handler that implements the listener interface without any listener annotation, which must keep being registered exactly once. Resolves spring-projects#5466 Signed-off-by: Sanghyuk Jung <sanghyuk.jung@navercorp.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #5466
ChunkOrientedStepBuilder#addAsStreamAndListenerregistered an item handler as a listener in two non-exclusive branches: once as the raw object (instanceof StepListener) and once as aStepListenerFactoryBeanproxy (isListener(...)). SinceAbstractListenerFactoryBean#getObjectresolves callbacks by interface as well as by annotation, an item handler that implements a listener interface and has a listener-annotated method was registered twice, and every interface callback fired twice per item.This change registers through
StepListenerFactoryBeanonly, restoring the 5.2.x behavior ofSimpleStepBuilder#registerAsStreamsAndListeners:isListener(...)already returnstruefor interface-only implementations, andgetObject()returns the delegate unchanged when no annotated methods are present (synthetic == false), so interface-only handlers are still registered as before.The added integration test fails on
mainwithexpected: <1> but was: <2>forbeforeProcess/afterProcesscounts and passes with this fix.