Skip to content

Relocate client proxies for public third-party normal-scoped beans to avoid requiring --add-opens #3502

Open

Description

@jamezp

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

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

  1. 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.web must open io.vertx.ext.web to weld.core.impl (for privateLookupIn + 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

  1. added 2 commits that reference this issue on Sep 3, 2026
    87cdb5c
    fb5498e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions