Skip to content

GH-9878: Fix ConcurrentModificationException in SpringIntegrationTest… #9879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

proggler23
Copy link
Contributor

…ExecutionListener

Fixes: gh-9878

* return new list in MockIntegrationContext.getAutoStartupCandidates()

@@ -111,7 +111,7 @@ public void afterSingletonsInstantiated() {
}

List<AbstractEndpoint> getAutoStartupCandidates() {
return this.autoStartupCandidates;
return new ArrayList<>(this.autoStartupCandidates);
Copy link
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
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
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
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.

@proggler23 proggler23 force-pushed the GH-9878 branch 3 times, most recently from b1faaa3 to f89429b Compare March 6, 2025 19:55
…ExecutionListener

    Fixes: gh-9878

    * return new list in MockIntegrationContext.getAutoStartupCandidates()

Signed-off-by: Alexander Hain <[email protected]>
@artembilan artembilan merged commit 3d16e59 into spring-projects:main Mar 6, 2025
3 checks passed
@artembilan
Copy link
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.

2 participants