gnodet-bot commented on code in PR #13545:
URL: https://github.com/apache/maven/pull/13545#discussion_r4282934634
##########
impl/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java:
##########
@@ -188,10 +189,35 @@ private Injector doBind(Key<?> key, Binding<?> binding) {
protected <U> Injector bind(Key<U> key, Binding<U> b) {
Set<Binding<?>> bindingSet = bindings.computeIfAbsent(key, $ -> new
HashSet<>());
- bindingSet.add(b);
+ if (bindingSet.stream().noneMatch(existing -> isSameBinding(existing,
b))) {
Review Comment:
💡 **Complexity note:** The old `bindingSet.add(b)` was O(1) amortized
(HashSet). The new `bindingSet.stream().noneMatch(isSameBinding)` is O(n) per
`bind()` call. For the typical small binding sets in Maven this is fine, but
worth noting in case a plugin registers many bindings for the same key.
##########
impl/maven-di/src/main/java/org/apache/maven/di/Injector.java:
##########
@@ -172,7 +181,7 @@ static Injector create() {
* @param key the key identifying the instance to retrieve
* @return an instance matching the requested key
* @throws NullPointerException if key is null
- * @throws IllegalStateException if the type cannot be provided
+ * @throws RuntimeException if no binding can be provided or bindings are
ambiguous
Review Comment:
⚠️ Same `@throws` precision issue as line 169 — `DIException` is the
concrete type.
```suggestion
* @throws DIException if no binding can be provided or bindings are
ambiguous
```
##########
impl/maven-di/src/main/java/org/apache/maven/di/Injector.java:
##########
@@ -157,7 +166,7 @@ static Injector create() {
* @param key the class representing the type to retrieve
* @return an instance of the requested type
* @throws NullPointerException if key is null
- * @throws IllegalStateException if the type cannot be provided
+ * @throws RuntimeException if no binding can be provided or bindings are
ambiguous
Review Comment:
⚠️ **Imprecise `@throws`:** `RuntimeException` is the hierarchy root —
callers cannot catch it meaningfully. The concrete type actually thrown is
`DIException` (which is a `RuntimeException`). Documenting the concrete type
makes the API contract discoverable and lets embedders write targeted catch
blocks.
```suggestion
* @throws DIException if no binding can be provided or bindings are
ambiguous
```
--
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]