Repository navigation
Description
On the Java module path, Weld requires --add-opens (WELD-2828 fixed the --add-reads) on a third-party module whenever an application injects a normal-scoped bean whose type lives in that module — e.g. a @RequestScoped producer that produces a public interface owned by another named module. Weld already avoids this for java.* and jakarta.* types by relocating their proxies into org.jboss.weld.generated.proxies.*. This request is to generalize that relocation to any public type in a named module whose package is not opened to Weld, eliminating the --add-opens requirement for those beans.
A CDI producer exposes a Vert.x type as a normal-scoped bean:
@Produces
@RequestScoped
RoutingContext routingContext() { ... } // io.vertx.ext.web.RoutingContext, module io.vertx.webRoutingContext is a public interface, exported from the io.vertx.web module. Because @RequestScoped is a normal scope, Weld generates a client proxy. On the module path this currently fails unless the application launches with:
--add-opens io.vertx.web/io.vertx.ext.web=weld.core.impl
By contrast, injecting a jakarta.ws.rs-owned normal-scoped type works with no flags, because those proxies are relocated.
Root cause (verified against source)
weld-core-impl, org.jboss.weld.bean.proxy:
ProxyFactory.getProxyClass()relocates a proxy into Weld's own namespace only for java/jakarta prefixes:
if (proxyClassName.startsWith(JAVA)) {
proxyClassName = proxyClassName.replaceFirst(JAVA, WELD_PROXY_PREFIX);
} else if (proxyClassName.startsWith(JAKARTA)) {
proxyClassName = proxyClassName.replaceFirst(JAKARTA, WELD_PROXY_PREFIX);
}For a producer, createCompoundProxyName() forces the proxy package to the produced type's package (mostSpecificClass.getPackage().getName()), so a RoutingContext proxy is named in io.vertx.ext.web.* and never matches the prefix check.
2. WeldDefaultProxyServices.defineClass() then dispatches purely on the proxy's name prefix:
if (className.startsWith(ProxyFactory.WELD_PROXY_PREFIX)) {
return defineWithClassLoader(className, ...); // Weld's own CL — needs nothing from target module
} else {
return defineWithMethodLookup(className, ..., originalClass, ...);
}Non-relocated names go through defineWithMethodLookup, which does MethodHandles.privateLookupIn(targetType, ...) and defines the proxy into the target package. That is what forces:
- opens:
io.vertx.webmust openio.vertx.ext.webtoweld.core.impl(forprivateLookupIn+defineClass), and - reads: the target module must read weld.core.impl and weld.api so the generated proxy can link the Weld interfaces it implements.
The defineWithClassLoader path (used by relocated java/jakarta proxies) needs neither.
Activity
Relocate client proxies for public third-party normal-scoped beans to…
Relocate client proxies for public third-party normal-scoped beans to…