jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.86k stars 1.91k forks source link

ContextHandler(anyHandler) NPE during .<init> logging 'because "this._vhosts" is null' #11220

Closed wsharten closed 9 months ago

wsharten commented 10 months ago

Jetty version(s) 12.0.5

Jetty Environment core

Java version/vendor openjdk version "21.0.1" 2023-10-17 OpenJDK Runtime Environment (build 21.0.1+12-29)

Mac OS Big Sur

Description ContextHandler(anyHandler) NPE during . logging call 'because "this._vhosts" is null'

Happens in the constructor when given any handler, including several examples from Jetty 12 docs.

Does not happen if handler is omitted, i.e. new ContextHandler()

How to reproduce?

  public static void main(String[] args) throws Exception {
    ContextHandler simpleContextHandler = new ContextHandler(new Handler.Abstract.NonBlocking() {
      @Override
      public boolean handle(Request request, Response response, Callback callback){
          callback.succeeded();
          return true;
      }
    });
  }

IDE: Eclipse 23, configured via maven dependencies

VM arguments:

-DJETTY_HOME=/Users/bill/Documents/workspace/worktracks -- this is irrelevant

Log/Stacktrace:

SLF4J(E): Failed toString() invocation on an object of type [org.eclipse.jetty.server.handler.ContextHandler]
SLF4J(E): Reported exception:
java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because "this._vhosts" is null
    at org.eclipse.jetty.server.handler.ContextHandler.getVirtualHosts(ContextHandler.java:391)
    at org.eclipse.jetty.server.handler.ContextHandler.toString(ContextHandler.java:1032)
    at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:291)
    at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:263)
    at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:225)
    at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:160)
    at ch.qos.logback.classic.spi.LoggingEvent.getFormattedMessage(LoggingEvent.java:397)
    at ch.qos.logback.classic.spi.LoggingEvent.prepareForDeferredProcessing(LoggingEvent.java:253)
    at ch.qos.logback.core.OutputStreamAppender.subAppend(OutputStreamAppender.java:226)
    at ch.qos.logback.core.OutputStreamAppender.append(OutputStreamAppender.java:102)
    at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:85)
    at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
    at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:272)
    at ch.qos.logback.classic.Logger.callAppenders(Logger.java:259)
    at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
    at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:419)
    at ch.qos.logback.classic.Logger.debug(Logger.java:495)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:419)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:317)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.updateBean(ContainerLifeCycle.java:802)
    at org.eclipse.jetty.server.Handler$Singleton.updateHandler(Handler.java:397)
    at org.eclipse.jetty.server.Handler$Wrapper.<init>(Handler.java:695)
    at org.eclipse.jetty.server.Handler$Wrapper.<init>(Handler.java:682)
    at org.eclipse.jetty.server.handler.ContextHandler.<init>(ContextHandler.java:177)
    at org.eclipse.jetty.server.handler.ContextHandler.<init>(ContextHandler.java:167)
    at worktrack.WorktracksServer.main(WorktracksServer.java:41)

Imports:

package mypackage;

import java.io.File;
import java.io.FileNotFoundException;
import java.time.Instant;

import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.util.Callback;
//import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.handler.SecuredRedirectHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.DefaultHandler;
import java.util.List;
joakime commented 10 months ago

Opened PR #11225

joakime commented 9 months ago

This is also being fixed in PR #11225