Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2370

ServletNameAttribute can throw NPE against request for non servlet application

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 2.3.12.Final
    • Servlet
    • Hide

      1. Enable access-log with adding %{SERVLET_NAME} to pattern in undertow subsystem in Wildfly (or JBoss EAP) configuration:

      $ diff -u standalone/configuration/standalone.xml.BAK standalone/configuration/standalone.xml
      --- standalone/configuration/standalone.xml.BAK    2024-01-24 11:27:36.000000000 +0900
      +++ standalone/configuration/standalone.xml    2024-04-04 00:22:41.629170474 +0900
      @@ -474,6 +474,7 @@
                       <host name="default-host" alias="localhost">
                           <location name="/" handler="welcome-content"/>
                           <http-invoker http-authentication-factory="application-http-authentication"/>
      +                    <access-log pattern="%h %l %u %t &quot;%r&quot; %s %b %{SERVLET_NAME}"/>
                       </host>
                   </server>
                   <servlet-container name="default">
      @@ -519,4 +520,4 @@
                   <remote-destination host="${jboss.mail.server.host:localhost}" port="${jboss.mail.server.port:25}"/>
               </outbound-socket-binding>
           </socket-binding-group>
      

      2. Send a request that is not handled by servlet application but handled by file handler (<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/> in the default configuration)

      $ curl -v http://localhost:8080/
      

      3. You will see NullPointerException in server.log. And no log entry is output to access-log.

      Show
      1. Enable access-log with adding %{SERVLET_NAME} to pattern in undertow subsystem in Wildfly (or JBoss EAP) configuration: $ diff -u standalone/configuration/standalone.xml.BAK standalone/configuration/standalone.xml --- standalone/configuration/standalone.xml.BAK    2024-01-24 11:27:36.000000000 +0900 +++ standalone/configuration/standalone.xml    2024-04-04 00:22:41.629170474 +0900 @@ -474,6 +474,7 @@                  <host name= " default -host" alias= "localhost" >                      <location name= "/" handler= "welcome-content" />                      <http-invoker http-authentication-factory= "application-http-authentication" /> +                    <access-log pattern= "%h %l %u %t &quot;%r&quot; %s %b %{SERVLET_NAME}" />                  </host>              </server>              <servlet-container name= " default " > @@ -519,4 +520,4 @@              <remote-destination host= "${jboss.mail.server.host:localhost}" port= "${jboss.mail.server.port:25}" />          </outbound-socket-binding>      </socket-binding-group> 2. Send a request that is not handled by servlet application but handled by file handler (<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/> in the default configuration) $ curl -v http: //localhost:8080/ 3. You will see NullPointerException in server.log. And no log entry is output to access-log.

      ServletNameAttribute (%{SERVLET_NAME}) can be added to access log format to output the servlet name which handled for the request.

      However, it can throw NullPointerException (NPE) when a request is not handled by the servlet application (for example, a request is handled by Undertow Handler like file handler in WildFly/JBoss EAP configuration). And no log entry is output to the access log when NPE occurs.
       

      ERROR [io.undertow.request] (default task-1) UT005071: Undertow request failed HttpServerExchange{ GET /}: java.lang.NullPointerException
      	at io.undertow.servlet@2.3.10.Final//io.undertow.servlet.attribute.ServletNameAttribute.readAttribute(ServletNameAttribute.java:46)
      	at io.undertow.core@2.3.10.Final//io.undertow.attribute.SubstituteEmptyWrapper$SubstituteEmptyAttribute.readAttribute(SubstituteEmptyWrapper.java:32)
      	at io.undertow.core@2.3.10.Final//io.undertow.attribute.CompositeExchangeAttribute.readAttribute(CompositeExchangeAttribute.java:42)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.accesslog.AccessLogHandler$AccessLogCompletionListener.exchangeEvent(AccessLogHandler.java:156)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.HttpServerExchange$ExchangeCompleteNextListener.proceed(HttpServerExchange.java:1983)
      	at org.wildfly.extension.undertow@31.0.0.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler$1.exchangeEvent(GlobalRequestControllerHandler.java:36)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.HttpServerExchange.invokeExchangeCompleteListeners(HttpServerExchange.java:1358)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.HttpServerExchange.terminateResponse(HttpServerExchange.java:1646)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.Connectors.terminateResponse(Connectors.java:182)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.protocol.http.ServerFixedLengthStreamSinkConduit.channelFinished(ServerFixedLengthStreamSinkConduit.java:58)
      	at io.undertow.core@2.3.10.Final//io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.exitFlush(AbstractFixedLengthStreamSinkConduit.java:316)
      	at io.undertow.core@2.3.10.Final//io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.flush(AbstractFixedLengthStreamSinkConduit.java:234)
      	at org.jboss.xnio@3.8.12.Final//org.xnio.conduits.ConduitStreamSinkChannel.flush(ConduitStreamSinkChannel.java:162)
      	at io.undertow.core@2.3.10.Final//io.undertow.channels.DetachableStreamSinkChannel.flush(DetachableStreamSinkChannel.java:119)
      	at io.undertow.core@2.3.10.Final//io.undertow.io.AsyncSenderImpl.close(AsyncSenderImpl.java:376)
      	at io.undertow.core@2.3.10.Final//io.undertow.io.DefaultIoCallback.onComplete(DefaultIoCallback.java:54)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.resource.PathResource$1ServerTask.run(PathResource.java:186)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.resource.PathResource$1ServerTask.onComplete(PathResource.java:209)
      	at io.undertow.core@2.3.10.Final//io.undertow.io.AsyncSenderImpl.invokeOnComplete(AsyncSenderImpl.java:435)
      	at io.undertow.core@2.3.10.Final//io.undertow.io.AsyncSenderImpl.send(AsyncSenderImpl.java:192)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.resource.PathResource$1ServerTask.run(PathResource.java:196)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.resource.PathResource.serveImpl(PathResource.java:265)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.resource.PathResource.serve(PathResource.java:121)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.handlers.resource.ResourceHandler$1.handleRequest(ResourceHandler.java:337)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
      	at io.undertow.core@2.3.10.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
      	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1348)
      	at org.jboss.xnio@3.8.12.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      

      It should not throw NPE. It should output just "-" when the request not handled by the servlet application.

            flaviarnn Flavia Rainone
            rhn-support-mmiura Masafumi Miura
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: