Skip to content
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

Update MicronautMetaServiceLoaderUtils.java to fix single threaded service loader #11229 #11326

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public List<S> collect(boolean allowFork) {
List<S> collection = new ArrayList<>(serviceEntries.size());
for (String serviceEntry : serviceEntries) {
S val = instantiate(serviceEntry, classLoader);
if (val != null && predicate != null && !predicate.test(val)) {
if (val != null && !collection.contains(val) && (predicate == null || predicate.test(val))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

collection.contains(val) might be a costly operation, so I wonder if it is required. Do the services implement a correct equals method, so that this would actually make a difference?

If it is required,can we use a set instead of a list and don't do this check?

Copy link
Contributor Author

@tbashour tbashour Nov 8, 2024

Choose a reason for hiding this comment

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

The parallel option has it (line 312)
if (result != null && !values.contains(result)) {

That's why I added it. If the check is not required, I would remove it ... I would prefer to remove it from both places to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we an remove it there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okak, I have committed the change

collection.add(val);
}
}
Expand Down