gnodet commented on code in PR #12117:
URL: https://github.com/apache/maven/pull/12117#discussion_r3279167732


##########
impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedConfigurationConverter.java:
##########
@@ -108,6 +111,56 @@ public Object fromConfiguration(
         }
     }
 
+    private Class<?> resolveClassForImplementationHint(
+            final Class<?> type, final PlexusConfiguration configuration, 
final ClassLoader loader)
+            throws ComponentConfigurationException {
+        try {
+            return super.getClassForImplementationHint(type, configuration, 
loader);
+        } catch (final ComponentConfigurationException e) {
+            if (type == null || !type.isSealed()) {
+                throw e;
+            }
+            final String implementation = 
configuration.getAttribute("implementation");
+            if (implementation == null || implementation.isEmpty()) {
+                throw e;
+            }
+            return getPermittedSubclass(type, implementation, configuration, 
e);
+        }
+    }
+
+    private Class<?> getPermittedSubclass(
+            final Class<?> type,
+            final String implementation,
+            final PlexusConfiguration configuration,
+            final ComponentConfigurationException cause)
+            throws ComponentConfigurationException {
+        final List<Class<?>> matches = new ArrayList<>();
+        for (Class<?> permittedSubclass : type.getPermittedSubclasses()) {
+            if (implementation.equals(permittedSubclass.getName())
+                    || 
implementation.equals(permittedSubclass.getCanonicalName())
+                    || 
implementation.equals(permittedSubclass.getSimpleName())) {

Review Comment:
   Missing `cause` in the ambiguity exception — the "not found" path includes 
it but this one does not, losing diagnostic context.
   
   ```suggestion
           throw new ComponentConfigurationException(
                   configuration,
                   "Implementation hint '" + implementation + "' is ambiguous 
for sealed type " + type.getName() + ": "
                           + matches.stream().map(Class::getName).toList(),
                   cause);
   ```



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