Skip to content

GH-9878: Fix ConcurrentModificationException in SpringIntegrationTest…#9879

Merged
artembilan merged 1 commit intospring-projects:mainfrom
proggler23:GH-9878
Mar 6, 2025
Merged

GH-9878: Fix ConcurrentModificationException in SpringIntegrationTest…#9879
artembilan merged 1 commit intospring-projects:mainfrom
proggler23:GH-9878

Conversation

@proggler23
Copy link
Copy Markdown
Contributor

…ExecutionListener

Fixes: gh-9878

* return new list in MockIntegrationContext.getAutoStartupCandidates()


List<AbstractEndpoint> getAutoStartupCandidates() {
return this.autoStartupCandidates;
return new ArrayList<>(this.autoStartupCandidates);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I'm OK with what you are suggesting, but this has to be like Collections.unmodifiableList() instead.
We indeed do like that in many other places where we return a collection from the object.
I missed this here because it is not public API, but as we see turns out it does not matter if we may deal with concurrent modifications. 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, I was just not returning unmodifiableList to not break any user, who is in fact modifying. but you're right, it's not public anyways

@SpringJUnitConfig
@ContextConfiguration(classes = MockIntegrationContextTests.Config.class)
@SpringIntegrationTest
public class MockIntegrationContextTests {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's just remove this new void class altogether!
I'm really not sure that registering beans in start()/stop() is OK idea, so I don't want to promote such a pattern with our tests.
Plus the fix is really simple and it is obvious that it is going to work in your project.

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, no asterisk imports.
Also, please, add your name to the @author list of this class.

…ExecutionListener

    Fixes: gh-9878

    * return new list in MockIntegrationContext.getAutoStartupCandidates()

Signed-off-by: Alexander Hain <Alexander.hain@cloudflight.io>
@artembilan artembilan merged commit 3d16e59 into spring-projects:main Mar 6, 2025
3 checks passed
@artembilan
Copy link
Copy Markdown
Member

@proggler23 ,

thank you very much for the contribution; looking forward for more!

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.

3 participants