title: NullPointerException when deploying JAX-RS RESTful service in Wildfly with RestEasy
body: <p>I'm trying to deploy a simple JAX-RS web service in Wildfly 21.0.0, but I get the following error in Wildfly logs:</p>
  <pre><code>[org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 334) RESTEASY002225: Deploying javax.ws.rs.core.Application: class restwebservices.MyRestApplication$Proxy$_$$_WeldClientProxy
  04:17:02,444 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 334) MSC000001: Failed to start service jboss.deployment.unit.&quot;lab8.war&quot;.undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit.&quot;lab8.war&quot;.undertow-deployment: java.lang.NullPointerException
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
          at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
          at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
          at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
          at java.lang.Thread.run(Thread.java:748)
          at org.jboss.threads.JBossThread.run(JBossThread.java:513)
  Caused by: java.lang.NullPointerException
          at com.sun.faces.mgbean.BeanManager$ScopeManager$SessionScopeHandler.handle(BeanManager.java:566)
          at com.sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(BeanManager.java:436)
          at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:388)
          at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:247)
          at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:200)
          at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:55)
          at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:156)
          at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:184)
          at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:91)
          at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
          at org.jboss.weld.module.web.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
          at com.sun.faces.application.applicationimpl.ExpressionLanguage.evaluateExpressionGet(ExpressionLanguage.java:165)
          at com.sun.faces.application.ApplicationImpl.evaluateExpressionGet(ApplicationImpl.java:205)
          at javax.faces.application.ApplicationWrapper.evaluateExpressionGet(ApplicationWrapper.java:729)
          at restwebservices.MyRestApplication.getClasses_aroundBody1$advice(MyRestApplication.java:30)
          at restwebservices.MyRestApplication.getClasses(MyRestApplication.java:1)
          at restwebservices.MyRestApplication$Proxy$_$$_WeldClientProxy.getClasses(Unknown Source)
          at org.jboss.resteasy.spi.ResteasyDeployment.processApplication(ResteasyDeployment.java:569)
          at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:403)
          at org.jboss.resteasy.spi.ResteasyDeployment.startInternal(ResteasyDeployment.java:288)
          at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:93)
          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:140)
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:42)
          at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
          at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
          at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
          at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:305)
          at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:145)
          at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:588)
          at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:559)
          at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
          at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
          at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:601)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:97)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78)
          ... 8 more
  
  04:17:02,450 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation (&quot;full-replace-deployment&quot;) failed - address: ([]) - failure description: {&quot;WFLYCTL0080: Failed services&quot; =&gt; {&quot;jboss.deployment.unit.\&quot;lab8.war\&quot;.undertow-deployment&quot; =&gt; &quot;java.lang.NullPointerException
      Caused by: java.lang.NullPointerException&quot;}}
  04:17:02,469 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0016: Replaced deployment &quot;lab8.war&quot; with deployment &quot;lab8.war&quot;
  04:17:02,469 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
  WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit.&quot;lab8.war&quot;.undertow-deployment: java.lang.NullPointerException
  </code></pre>
  <p>These are the dependencies for RestEasy in my <code>pom.xml</code>:</p>
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-servlet-initializer&lt;/artifactId&gt;
              &lt;version&gt;3.0.14.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-client&lt;/artifactId&gt;
              &lt;version&gt;3.0.14.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
              &lt;version&gt;3.0.14.Final&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  <p>I did not declare any servlet in the web.xml, because from what I understand, resteasy servlet-initializer should handle that.</p>
  <p>This is my Application class:</p>
  <pre><code>@ApplicationPath(&quot;/rest&quot;)
  public class MyRestApplication extends Application {
  
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; resourceClasses = new HashSet&lt;Class&lt;?&gt;&gt;();
          resourceClasses.add(AddDocumentService.class);
          return resourceClasses;
      }
  }
  </code></pre>
  <p>And this is my service implementation:</p>
  <pre><code>@Path(&quot;/addDocument&quot;)
  public class AddDocumentService{
  
      @POST
      @Produces(&quot;text/plain&quot;)
      public String addDocument() {
          return &quot;IT'S OK&quot;;
      }
  }
  </code></pre>
  <p>Can someone please explain the error to me?</p>
  <p>UPDATE:</p>
  <p>I managed to deploy the application but I still get a weird NullPointerException when I call my service. This is the stacktrace:</p>
  <pre><code>10:36:22,819 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /lab8/rest/addDocument: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
          at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:82)
          at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:346)
          at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:193)
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:457)
          at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
          at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
          at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
          at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138)
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215)
          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:245)
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:61)
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
          at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
          at io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
          at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
          at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
          at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
          at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
          at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
          at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
          at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
          at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
          at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
          at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
          at io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
          at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
          at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
          at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
          at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
          at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
          at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
          at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
          at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
          at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
          at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
          at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
          at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
          at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
          at java.lang.Thread.run(Thread.java:748)
  Caused by: java.lang.NullPointerException
          at restwebservices.resource.AddDocumentService.getDocument_aroundBody1$advice(AddDocumentService.java:30)
          at restwebservices.resource.AddDocumentService.getDocument(AddDocumentService.java:1)
          at restwebservices.resource.AddDocumentService$Proxy$_$$_WeldClientProxy.getDocument(Unknown Source)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:138)
          at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:543)
          at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:432)
          at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:393)
          at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
          at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:395)
          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:364)
          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:337)
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:440)
          ... 59 more
  </code></pre>
  <p>I changed the dependencies and the Application class:</p>
  <pre><code>@ApplicationPath(&quot;/rest&quot;)
  public class MyRestApplication extends Application {
  
  }
  </code></pre>
  <p>Could it be something from my beans.xml?</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee
          http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd&quot;
         bean-discovery-mode=&quot;all&quot;&gt;
      &lt;interceptors&gt;
          &lt;class&gt;CDI.interceptors.LoggerInterceptor&lt;/class&gt;
      &lt;/interceptors&gt;
  &lt;/beans&gt;
  </code></pre>