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


##########
impl/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -99,26 +109,28 @@ public DefaultClassRealmManager(
         this.containerRealm = coreRealm.getRealm();
         this.delegates = delegates;
 
-        Map<String, ClassLoader> foreignImports = 
exports.getExportedPackages();
-
-        this.mavenApiRealm = createRealm(
-                API_REALMID,
-                RealmType.Core,
-                null /* parent */,
-                null /* parentImports */,
-                foreignImports,
-                null /* artifacts */);
-
-        Map<String, ClassLoader> apiV4Imports = new HashMap<>();
-        apiV4Imports.put("org.apache.maven.api", containerRealm);
-        apiV4Imports.put("org.slf4j", containerRealm);
-        this.maven4ApiRealm = createRealm(API_V4_REALMID, RealmType.Core, 
null, null, apiV4Imports, null);
-
         this.providedArtifacts = exports.getExportedArtifacts();
 
         this.providedArtifactsV4 = providedArtifacts.stream()
                 .filter(ga -> ga.startsWith("org.apache.maven:maven-api-"))
                 .collect(Collectors.toSet());
+
+        // When realms are defined in m2.conf they already exist. For 
embedders and
+        // tests that skip m2.conf, create them here as a fallback.
+        ensureApiRealms(exports);
+    }
+
+    private void ensureApiRealms(CoreExports exports) {
+        if (world.getClassRealm(API_REALMID) == null) {
+            Map<String, ClassLoader> foreignImports = 
exports.getExportedPackages();
+            createRealm(API_REALMID, RealmType.Core, null, null, 
foreignImports, null);
+        }
+        if (world.getClassRealm(API_V4_REALMID) == null) {
+            Map<String, ClassLoader> apiV4Imports = new HashMap<>();

Review Comment:
   🔵 **N1: Fully-qualified `java.util.HashMap` after import removed**
   
   `import java.util.HashMap` was removed but this site uses the 
fully-qualified name. Restore the import and use the unqualified form:
   
   ```suggestion
               Map<String, ClassLoader> apiV4Imports = new HashMap<>();
   ```



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