Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2667

ClassNotFoundException with WeldDefaultProxyServices for JDK 11+

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 3.1.7.SP1
    • Proxies
    • None
    • Undefined

      I have an application that works fine with 3.1.6.Final but is broken with 3.1.7.SP1.

      After some investigation, I think I've determined the cause. Suppose you have:

      • A classloader P
      • A classloader C that has P as its parent
      • Weld's classes are loaded from C
      • The class X that needs to be proxied is loaded from P

      The JDK 11+ version of WeldDefaultProxyServices uses MethodHandles#privateLookupIn() to define the proxy class. It passes X as the targetClass, and Lookup uses X's ClassLoader (P) when defining/loading classes. But that does not work because Weld adds a bunch of its own interfaces to the proxy class, and those interfaces are not available from P, so they cannot be loaded and the attempt to define the class fails.

      Full stack trace:

       org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load proxy class for bean Configurator Bean [class com.sg.song.service.ca.cdi.ServiceContextExtension, types: Object, ServiceContext, qualifiers: @Any @Default] with class class java.lang.Object
      	at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:392) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.run(ProxyFactory.java:345) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:337) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyFactory.create(ClientProxyFactory.java:83) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:205) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:195) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyProvider.access$100(ClientProxyProvider.java:44) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyProvider$CreateClientProxy.apply(ClientProxyProvider.java:52) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyProvider$CreateClientProxy.apply(ClientProxyProvider.java:48) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.lambda$new$0(ReentrantMapBackedComputingCache.java:55) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.LazyValueHolder$1.computeValue(LazyValueHolder.java:32) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:46) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:72) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getCastValue(ReentrantMapBackedComputingCache.java:78) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:229) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:688) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:345) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:356) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:69) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.contexts.AbstractContext.get(AbstractContext.java:96) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.get(ContextualInstanceStrategy.java:140) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:123) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:158) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:180) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.ParameterInjectionPointImpl.getValueToInject(ParameterInjectionPointImpl.java:76) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.StaticMethodInjectionPoint.getParameterValues(StaticMethodInjectionPoint.java:134) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.injection.MethodInvocationStrategy$DefaultMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:144) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:123) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124) ~[jakarta.enterprise.cdi-api-2.0.2.jar:?]
      	at org.jboss.weld.util.Observers.notify(Observers.java:166) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:159) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:632) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.environment.se.WeldContainer.fireContainerInitializedEvent(WeldContainer.java:236) ~[weld-se-core-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.environment.se.WeldContainer.endInitialization(WeldContainer.java:188) ~[weld-se-core-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.environment.se.Weld.initialize(Weld.java:817) ~[weld-se-core-3.1.7.SP1.jar:3.1.7.SP1]
      	at com.sg.song.service.ca.CaPlugin$1.run(CaPlugin.java:43) [classes/:?]
      Caused by: java.lang.NoClassDefFoundError: org/jboss/weld/proxy/WeldConstruct
      	at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]
      	at java.lang.System$2.defineClass(System.java:2131) ~[?:?]
      	at java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:962) ~[?:?]
      	at org.jboss.weld.bean.proxy.util.WeldDefaultProxyServices.defineWithMethodLookup(WeldDefaultProxyServices.java:163) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.util.WeldDefaultProxyServices.defineClass(WeldDefaultProxyServices.java:69) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.toClass(ProxyFactory.java:920) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:478) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:384) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	... 56 more
      Caused by: java.lang.ClassNotFoundException: org.jboss.weld.proxy.WeldConstruct
      	at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[?:?]
      	at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[?:?]
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[?:?]
      	at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]
      	at java.lang.System$2.defineClass(System.java:2131) ~[?:?]
      	at java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:962) ~[?:?]
      	at org.jboss.weld.bean.proxy.util.WeldDefaultProxyServices.defineWithMethodLookup(WeldDefaultProxyServices.java:163) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.util.WeldDefaultProxyServices.defineClass(WeldDefaultProxyServices.java:69) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.toClass(ProxyFactory.java:920) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:478) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:384) ~[weld-core-impl-3.1.7.SP1.jar:3.1.7.SP1]
      	... 56 more

            Unassigned Unassigned
            rdicroce Richard DiCroce (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: