Pankraz76 commented on code in PR #2425:
URL: https://github.com/apache/maven/pull/2425#discussion_r2124918459
##########
impl/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java:
##########
@@ -220,7 +220,13 @@ public <Q> Supplier<Q> doGetCompiledBinding(Dependency<Q>
dep) {
if (key.getRawType() == List.class) {
Set<Binding<Object>> res2 = getBindings(key.getTypeParameter(0));
if (res2 != null) {
- List<Supplier<Object>> list =
res2.stream().map(this::compile).collect(Collectors.toList());
+ // Sort bindings by priority (highest first) for deterministic
ordering
+ List<Binding<Object>> sortedBindings = new ArrayList<>(res2);
+ Comparator<Binding<Object>> comparing =
Comparator.comparing(Binding::getPriority);
+ sortedBindings.sort(comparing.reversed());
+
+ List<Supplier<Object>> list =
+
sortedBindings.stream().map(this::compile).collect(Collectors.toList());
//noinspection unchecked
return () -> (Q) list(list, Supplier::get);
Review Comment:
considering this domain logic, might use OOP implementing `comparable` as
its wont hurt nobody giving special attention and cohesion to core logic.
<img width="1862" alt="image"
src="https://github.com/user-attachments/assets/416d7025-ea50-4bca-9d00-afa3b1fc00a2"
/>
##########
impl/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java:
##########
@@ -220,7 +220,13 @@ public <Q> Supplier<Q> doGetCompiledBinding(Dependency<Q>
dep) {
if (key.getRawType() == List.class) {
Set<Binding<Object>> res2 = getBindings(key.getTypeParameter(0));
if (res2 != null) {
- List<Supplier<Object>> list =
res2.stream().map(this::compile).collect(Collectors.toList());
+ // Sort bindings by priority (highest first) for deterministic
ordering
+ List<Binding<Object>> sortedBindings = new ArrayList<>(res2);
+ Comparator<Binding<Object>> comparing =
Comparator.comparing(Binding::getPriority);
+ sortedBindings.sort(comparing.reversed());
+
+ List<Supplier<Object>> list =
+
sortedBindings.stream().map(this::compile).collect(Collectors.toList());
Review Comment:
```java
List<Binding<Object>> sortedBindings = new ArrayList<>(res2);
sortedBindings.sort(Comparator.reverseOrder());
//noinspection unchecked
return () -> (Q)
list(sortedBindings.stream().map(this::compile).collect(Collectors.toList()),
Supplier::get);
```
```java
@Override
public int compareTo(Binding<Object> objectBinding) {
return Integer.compare(this.priority, objectBinding.priority);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]