Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-1968

MP Health Check /health throws NPE if HealthCheck implementation does not specify state

    Details

      Description

      Having a HealthCheck implemented without setting the state (calling up() or down() - which is a common programmer error) :

      @Health
      @ApplicationScoped
      public class DiskSpaceHealthCheck implements HealthCheck {
          @Override
          public HealthCheckResponse call() {
              HealthCheckResponseBuilder builder = HealthCheckResponse.named("disk-space-check");
              for (FileStore store : FileSystems.getDefault().getFileStores()) {
                  try {
                      builder.withData("free.disk." + store.name(), store.getUsableSpace());
                  } catch (IOException e) {
                      // ignore
                  }
              }
              //Here is missing up() or down() call
              return builder.build();
          }
      }
      

      Throws the following error:

      2018-04-12 02:30:38,151 ERROR [io.undertow.request] (default I/O-7) UT005071: Undertow request failed HttpServerExchange{ GET /health request {Accept=[*/*], Connection=[keep-alive], Accept-Encoding=[gzip, deflate], User-Agent=[HTTPie/0.9.4], Host=[localhost:8080]} response {}}: java.lang.NullPointerException
      	at org.wildfly.swarm.microprofile.health.runtime.HttpContexts.toJson(HttpContexts.java:167)
      	at org.wildfly.swarm.microprofile.health.runtime.HttpContexts.proxyRequestsCDI(HttpContexts.java:104)
      	at org.wildfly.swarm.microprofile.health.runtime.HttpContexts.handleRequest(HttpContexts.java:73)
      	at org.wildfly.swarm.microprofile.health.runtime.SecureHttpContexts.handleRequest(SecureHttpContexts.java:83)
      	at org.wildfly.extension.undertow.Host$HostRootHandler.handleRequest(Host.java:345)
      	at io.undertow.server.handlers.NameVirtualHostHandler.handleRequest(NameVirtualHostHandler.java:64)
      	at io.undertow.server.handlers.error.SimpleErrorPageHandler.handleRequest(SimpleErrorPageHandler.java:78)
      	at io.undertow.server.handlers.CanonicalPathHandler.handleRequest(CanonicalPathHandler.java:49)
      	at org.wildfly.extension.undertow.Server$DefaultHostHandler.handleRequest(Server.java:189)
      	at io.undertow.server.handlers.ChannelUpgradeHandler.handleRequest(ChannelUpgradeHandler.java:211)
      	at io.undertow.server.handlers.DisallowedMethodsHandler.handleRequest(DisallowedMethodsHandler.java:61)
      	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
      	at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:254)
      	at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136)
      	at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:148)
      	at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:92)
      	at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:51)
      	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
      	at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:291)
      	at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:286)
      	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
      	at org.xnio.nio.QueuedNioTcpServer$1.run(QueuedNioTcpServer.java:131)
      	at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:612)
      	at org.xnio.nio.WorkerThread.run(WorkerThread.java:479)
      

      This probably may be a bug in the MP Health Check implementation: https://github.com/wildfly-swarm/wildfly-swarm/blob/master/client-apis/health-api/src/main/java/org/wildfly/swarm/microprofile/health/BuilderImpl.java#L34

      I'd expect a friendlier message saying that the Builder is not built correctly or assume UP as the default state (which covers the majority of use cases).

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                sbiarozk Sergey Beryozkin
                Reporter:
                gastaldi George Gastaldi
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: