gnodet-bot commented on code in PR #13942:
URL: https://github.com/apache/maven/pull/13942#discussion_r4522559116


##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java:
##########
@@ -579,7 +579,7 @@ private <T> T loadV4Mojo(
             injector.bindInstance(org.apache.maven.api.plugin.Log.class, log);
 
             Map<Class<? extends Service>, Supplier<? extends Service>> 
services = sessionV4.getAllServices();
-            services.forEach((itf, svc) -> 
injector.bindSupplier((Class<Service>) itf, (Supplier<Service>) svc));
+            services.forEach((itf, svc) -> 
injector.bindSupplier((Class<Service>) itf, (Supplier<Service>) svc, -10));

Review Comment:
   💡 **Magic number:** `-10` has no explanation at the call site. Consider 
extracting it as a named constant in `Injector` or `DefaultMavenPluginManager`, 
e.g.:
   ```suggestion
               services.forEach((itf, svc) -> 
injector.bindSupplier((Class<Service>) itf, (Supplier<Service>) svc, 
Injector.SESSION_SERVICE_PRIORITY));
   ```
   or at minimum a comment: `// lower than @Provides default (0), so plugins 
can override`



##########
impl/maven-di/src/main/java/org/apache/maven/di/Injector.java:
##########
@@ -147,6 +147,23 @@ static Injector create() {
     @Nonnull
     <T> Injector bindSupplier(@Nonnull Class<T> cls, @Nonnull Supplier<T> 
supplier);
 
+    /**
+     * Binds a supplier to a class with an explicit priority.
+     * <p>
+     * A lower priority value means the binding will be overridden by any 
binding with a higher priority.
+     * Use a negative priority (e.g. {@code -10}) to register a fallback 
binding that yields to
+     * plugin-provided {@code @Provides} methods (which default to priority 
{@code 0}).
+     *
+     * @param <T> the type of the instance
+     * @param cls the class to bind to
+     * @param supplier the supplier to use for injection
+     * @param priority the binding priority
+     * @return this injector instance for method chaining
+     * @throws NullPointerException if either parameter is null

Review Comment:
   ⚠️ **Javadoc wording:** `"if either parameter is null"` says *either* but 
the method has three parameters (`cls`, `supplier`, `priority`). Since 
`priority` is a primitive `int` it cannot be null, but the wording is 
misleading. Suggest being explicit:
   ```suggestion
        * @throws NullPointerException if {@code cls} or {@code supplier} is 
null
   ```



-- 
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]

Reply via email to