You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "cstamas (via GitHub)" <gi...@apache.org> on 2026/03/26 12:18:03 UTC

[PR] EXPERIMENT: Core Override Types and support [maven]

cstamas opened a new pull request, #11849:
URL: https://github.com/apache/maven/pull/11849

   This is a hack, that allows a plugins to _override_ Maven Core exported artifact and replace it with "own", for example to use Slf4j 2.x instead of core exported 1.x one.


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] EXPERIMENT: Core Override Type and support for it [maven]

Posted by "gnodet (via GitHub) via issues" <is...@maven.apache.org>.
gnodet commented on code in PR #11849:
URL: https://github.com/apache/maven/pull/11849#discussion_r4797949171


##########
maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -229,8 +252,13 @@ public ClassRealm createExtensionRealm(Plugin plugin, List<Artifact> artifacts)
         return createRealm(getKey(plugin, true), RealmType.Extension, parent, null, foreignImports, artifacts);
     }
 
+    private boolean isCoreOverrideArtifact(Artifact artifact) {
+        return "core-override-jar".equals(artifact.getProperties().get("type"));

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   **Potential NullPointerException**: `artifact.getProperties()` can return null if the artifact has no properties set. This will cause an NPE when calling `.get("type")`.
   
   **Recommendation**: Add a null check:
   ```java
   private boolean isCoreOverrideArtifact(Artifact artifact) {
       Map<String, String> props = artifact.getProperties();
       return props != null && "core-override-jar".equals(props.get("type"));
   }
   ```



##########
maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -190,6 +195,24 @@ private ClassRealm createRealm(
 
         wireRealm(classRealm, parentImports, foreignImports);
 
+        if (!coreOverrides.isEmpty()) {
+            ClassRealm overrideClassRealm = newRealm(baseRealmId + "-core-override");
+            for (Artifact coreOverride : coreOverrides) {
+                try {
+                    overrideClassRealm.addURL(coreOverride.getFile().toURI().toURL());
+                } catch (MalformedURLException e) {
+                    // Not going to happen
+                    logger.error(e.getMessage(), e);
+                }
+            }
+            // collect Gs (and assume packages == G for the experiment sake)
+            Set<String> packages =

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   **Overly simplistic package assumption**: The comment acknowledges this is "for the experiment sake," but assuming `groupId == package` will fail for most real-world artifacts. For example:
   - `org.slf4j:slf4j-api` has packages like `org.slf4j`, `org.slf4j.spi`, `org.slf4j.helpers`, etc.
   - Just importing `org.slf4j` won't cover all the necessary packages
   
   This means the override mechanism won't actually work correctly for the stated SLF4J 2.x use case without manually specifying all packages.
   
   **Recommendation**: 
   - Either scan the JAR to discover actual packages (more robust)
   - Or require explicit package specification in plugin configuration
   - Document this limitation clearly if keeping the simplification



##########
maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -190,6 +195,24 @@ private ClassRealm createRealm(
 
         wireRealm(classRealm, parentImports, foreignImports);
 
+        if (!coreOverrides.isEmpty()) {
+            ClassRealm overrideClassRealm = newRealm(baseRealmId + "-core-override");

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   **ClassRealm lifecycle management**: The `overrideClassRealm` is created but its lifecycle isn't managed:
   - When/how is it disposed?
   - Does it need to be tracked somewhere?
   - What happens if `createRealm` is called multiple times with the same `baseRealmId`?
   
   The realm ID `baseRealmId + "-core-override"` could potentially conflict if realms aren't properly cleaned up.
   
   **Recommendation**: Consider adding the override realm to a tracking structure or documenting its lifecycle expectations.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] EXPERIMENT: Core Override Type and support for it [maven]

Posted by "gnodet (via GitHub) via issues" <is...@maven.apache.org>.
gnodet commented on code in PR #11849:
URL: https://github.com/apache/maven/pull/11849#discussion_r4797954286


##########
maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -190,6 +195,24 @@ private ClassRealm createRealm(
 
         wireRealm(classRealm, parentImports, foreignImports);
 
+        if (!coreOverrides.isEmpty()) {

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   **Security considerations**: This feature allows plugins to override Maven Core dependencies, which creates a significant security surface:
   
   1. **Supply chain attacks**: A malicious or compromised plugin could override security-critical libraries (logging frameworks, XML parsers, etc.) with vulnerable or backdoored versions
   2. **Privilege escalation**: Overriding core libraries could allow plugins to bypass Maven's security controls or classloader isolation
   3. **Trust boundary violation**: Maven core dependencies are typically considered part of Maven's trusted codebase, but this feature allows untrusted plugin code to inject replacements
   
   **Questions for discussion**:
   - Should there be an allowlist of which artifacts can be overridden?
   - Should this feature require an explicit opt-in flag (similar to `-Dmaven.plugin.validation=VERBOSE`)?
   - Should there be audit logging when core overrides are used?
   - For the Maven 3.9.x branch specifically, is this considered too risky for a maintenance branch?
   
   Even as an experiment, it's worth documenting the security implications and considering mitigation strategies.



##########
maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml:
##########
@@ -53,6 +53,21 @@ Artifact handlers are required by the dependency resolution mechanism.
       </configuration>
     </component>
 
+    <!--
+     | core override JAR
+     |-->
+    <component>
+      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
+      <role-hint>core-override-jar</role-hint>
+      <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
+      <configuration>
+        <type>core-override-jar</type>
+        <extension>jar</extension>
+        <language>java</language>
+        <addedToClasspath>true</addedToClasspath>
+      </configuration>

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   **Artifact handler configuration looks correct**. The `core-override-jar` handler is properly configured:
   - Extends to `.jar` files ✓
   - Marked as `addedToClasspath=true` ✓  
   - Uses Java language ✓
   
   This configuration mirrors the standard `jar` handler appropriately.
   
   **Minor note**: The only difference from a regular JAR is the type name. Consider whether any other properties should differ (e.g., should it have a special `includesDependencies` setting?).



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] EXPERIMENT: Core Override Type and support for it [maven]

Posted by "gnodet (via GitHub) via issues" <is...@maven.apache.org>.
gnodet commented on code in PR #11849:
URL: https://github.com/apache/maven/pull/11849#discussion_r4797951722


##########
maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -229,8 +252,13 @@ public ClassRealm createExtensionRealm(Plugin plugin, List<Artifact> artifacts)
         return createRealm(getKey(plugin, true), RealmType.Extension, parent, null, foreignImports, artifacts);
     }
 
+    private boolean isCoreOverrideArtifact(Artifact artifact) {
+        return "core-override-jar".equals(artifact.getProperties().get("type"));
+    }
+
     private boolean isProvidedArtifact(Artifact artifact) {
-        return providedArtifacts.contains(artifact.getGroupId() + ":" + artifact.getArtifactId());
+        return !isCoreOverrideArtifact(artifact)

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   **Semantic change to `isProvidedArtifact`**: This change means that artifacts marked as `core-override-jar` will return `false` from `isProvidedArtifact` even if they're in the `providedArtifacts` set.
   
   This might be intentional (you want core-override artifacts to be included even if normally provided), but it changes the contract of this method in a subtle way.
   
   **Questions**:
   1. Is this the intended behavior? Should core-override artifacts bypass the provided check?
   2. Should this be documented or the method renamed to reflect its new behavior?
   3. What happens if someone tries to override an artifact that's in `providedArtifacts`?



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org