gnodet opened a new pull request, #13878:
URL: https://github.com/apache/maven/pull/13878
## Problem
When `InjectorImpl.doGetCompiledBinding()` is asked to resolve a `List<T>` or
`Map<String,T>` and no bindings are registered for type `T`, it falls through
to `throw new DIException(...)`. This violates the contract of
`Lookup.lookupList()`
and `Lookup.lookupMap()`, which document that they may return empty
collections.
The root cause is in `getBindings()`: it returns `null` (not an empty set)
when
the type is unknown, and the collection paths did not handle the `null` case.
A secondary bug in `ApiRunner`: `new Key<List<T>>() {}` suffers from type
erasure —
`getTypeParameter(0)` returns `Object`, not `T`. This was masked by the
try/catch
workaround callers added.
## Fix
- **`InjectorImpl`**: return `List.of()` / `Map.of()` when `getBindings()`
returns
`null` for the element type. No bindings = empty collection, not an error.
- **`ApiRunner`**: replace anonymous `Key<List<T>>` with
`Key.ofType(Types.parameterizedType(...))`
to correctly preserve the generic type at runtime; remove now-unnecessary
try/catch.
- **Javadoc** on `doGetCompiledBinding()` documenting the resolution rules
for scalar
vs. collection keys.
## Related
Part of the fix for #13701 / MNG-13520 (listener discovery via SpiService).
The
`lookupList(Listener.class)` call in `AbstractSession.getListeners()` was
silently
returning an empty list due to the type-erasure bug, or throwing a
`DIException`
caught and swallowed by callers.
--
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]