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

NullPointerException due to decorated object not having a CDI compatible constructor

    Details

    • Steps to Reproduce:
      Hide

      create a minimal JSR 356 WebSocket endpoint class

      create a ServletContextListener that explicitly registers the WebSocket endpoint
      ServerContainer container = (ServerContainer)context.getServletContext().getAttribute(ServerContainer.class.getName());
      container.addEndpoint( SomeWebSocketEnpoint.class);

      Run it in Jetty with the following in the web.xml or override-web.xml:

      <context-param>
      <param-name>org.eclipse.jetty.websocket.jsr356</param-name>
      <param-value>true</param-value>
      </context-param>

      Show
      create a minimal JSR 356 WebSocket endpoint class create a ServletContextListener that explicitly registers the WebSocket endpoint ServerContainer container = (ServerContainer)context.getServletContext().getAttribute(ServerContainer.class.getName()); container.addEndpoint( SomeWebSocketEnpoint.class); Run it in Jetty with the following in the web.xml or override-web.xml: <context-param> <param-name>org.eclipse.jetty.websocket.jsr356</param-name> <param-value>true</param-value> </context-param>

      Description

      I am trying to use Errai WebSocket support running in Jetty by manually registering the WebSocket endpoint in a ServletContextListener using the following code:

       ServerContainer container = (ServerContainer)context.getServletContext().getAttribute(ServerContainer.class.getName());
      container.addEndpoint( ErraiWebSocketEndpoint.class);
      

      When the Jetty starts up and I try to access the WebSocket endpoint the following exception is thrown:

      java.lang.NullPointerException
      	at org.jboss.weld.injection.InjectionPointFactory.getParameterInjectionPoints(InjectionPointFactory.java:249)
      	at org.jboss.weld.injection.AbstractCallableInjectionPoint.<init>(AbstractCallableInjectionPoint.java:52)
      	at org.jboss.weld.injection.ConstructorInjectionPoint.<init>(ConstructorInjectionPoint.java:63)
      	at org.jboss.weld.injection.InjectionPointFactory.createConstructorInjectionPoint(InjectionPointFactory.java:174)
      	at org.jboss.weld.injection.producer.DefaultInstantiator.<init>(DefaultInstantiator.java:46)
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.initInstantiator(BasicInjectionTarget.java:178)
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.<init>(BasicInjectionTarget.java:98)
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.<init>(BasicInjectionTarget.java:82)
      	at org.jboss.weld.injection.producer.BeanInjectionTarget.<init>(BeanInjectionTarget.java:58)
      	at org.jboss.weld.injection.producer.WeldInjectionTargetBuilderImpl.buildInternal(WeldInjectionTargetBuilderImpl.java:110)
      	at org.jboss.weld.injection.producer.WeldInjectionTargetBuilderImpl.run(WeldInjectionTargetBuilderImpl.java:97)
      	at org.jboss.weld.injection.producer.WeldInjectionTargetBuilderImpl.build(WeldInjectionTargetBuilderImpl.java:92)
      	at org.jboss.weld.environment.servlet.inject.AbstractInjector$1.load(AbstractInjector.java:54)
      	at org.jboss.weld.environment.servlet.inject.AbstractInjector$1.load(AbstractInjector.java:47)
      	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
      	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
      	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
      	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
      	at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
      	at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
      	at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
      	at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:49)
      	at org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue(LoadingCacheUtils.java:74)
      	at org.jboss.weld.environment.servlet.inject.AbstractInjector.inject(AbstractInjector.java:60)
      	at org.jboss.weld.environment.jetty.JettyWeldInjector.inject(JettyWeldInjector.java:15)
      	at org.jboss.weld.environment.jetty.WeldDecorator.decorate(WeldDecorator.java:105)
      	at org.eclipse.jetty.util.DecoratedObjectFactory.decorate(DecoratedObjectFactory.java:77)
      	at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:175)
      	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:207)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
      	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
      	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:513)
      	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
      	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1156)
      	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
      	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
      	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1088)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
      	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
      	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
      	at org.eclipse.jetty.server.Server.handle(Server.java:517)
      	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:306)
      	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
      	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
      	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
      	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
      	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
      	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
      	at java.lang.Thread.run(Thread.java:745)
      

      This error appears to originate from Weld attempting to decorate the provide object by attempting to load the class definition from cache that in turns reflects on the class in an attempt to identify an injection compatible constructor. In this case the Jetty org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance class does not have a CDI compatible constructor and in actuality does not have any CDI injection points either.

      After analysis of the Weld code base I made the attached minor alteration to abort constructor reflection for parameters if a CDI compatible constructor is not identified. Since DefaultInstantiator is coded to support a null constructor definition I believe the change is sound although I have not performed any extended testing beyond confirming it fixed the NPE above.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mkouba Martin Kouba
                Reporter:
                aanderson1776 Aaron Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: