gnodet commented on PR #12551:
URL: https://github.com/apache/maven/pull/12551#issuecomment-5096134485

   ### Update: TCCL + Realm Visibility Root Cause
   
   Dug deeper — the issue is the interaction between 
`DefaultMaven.callListeners()` and Sisu 1.1.0's new realm-based JSR330 
filtering.
   
   **The chain:**
   
   1. `DefaultMaven.callListeners()` (line 376) sets 
`Thread.currentThread().setContextClassLoader(listener.getClass().getClassLoader())`
 — i.e., TCCL = **Mimir's extension realm** 
(`coreExtension>eu.maveniverse.maven.mimir:extension3:0.12.0`)
   
   2. Mimir's `afterSessionStart` triggers lazy component resolution (needs 
`NameMapper` map via artifact resolution)
   
   3. In Sisu 1.1.0, `DefaultBeanLocator.locate()` now wraps results in 
`FilteredBeans` (new in 1.1.0 — previously only `DefaultPlexusBeanLocator` did 
realm filtering):
      ```java
      // DefaultPlexusContainer constructor (1.1.0):
      ((DefaultBeanLocator) qualifiedBeanLocator)
          .setBeanEntryPredicateSupplier(realmManager::visibilityPredicate);
      ```
   
   4. `FilteredBeans` calls `RealmManager.contextRealm()` which walks the TCCL 
looking for a `ClassRealm`:
      ```java
      for (ClassLoader tccl = Thread.currentThread().getContextClassLoader(); 
           tccl != null; tccl = tccl.getParent()) {
          if (tccl instanceof ClassRealm) return (ClassRealm) tccl;
      }
      ```
   
   5. Returns **Mimir's realm** → `visibleRealmNames()` computes what's visible 
from that realm → NameMapper beans (bound in `plexus.core`) are **filtered 
out** → `known ones: []`
   
   **Why Maven 3 / Sisu 1.0.1 works:** In 1.0.1, `DefaultBeanLocator.locate()` 
returned `LocatedBeans` directly with **no realm filter**. Realm filtering only 
applied to `DefaultPlexusBeanLocator.locate()` (Plexus `container.lookup()`). 
Since the Maven DI bridge and JSR330 injection bypassed Plexus lookups, they 
saw all beans regardless of realm.
   
   **Extension realm setup:** Mimir uses the default `self-first` strategy 
(`realm.setParentRealm(parentRealm)`), but the Sisu 1.1.0 visibility predicate 
apparently doesn't traverse parent realms to include their beans.
   
   **Possible fix directions:**
   - Configure `cc.setJSR330ComponentVisibilityFollowsPlexusVisibility(false)` 
in `PlexusContainerCapsuleFactory` (line ~107) — but this would undo the #12522 
fix
   - Ensure `callListeners()` sets TCCL to the **container realm** instead of 
the listener's classloader before calling lifecycle participants
   - Update the extension realm setup to ensure core realm beans are visible 
under the new filtering


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