Bug 65476 - Examples web application fails to start with Java 8 (NullPointerException at ExamplesConfig)
Summary: Examples web application fails to start with Java 8 (NullPointerException at ...
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Examples (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2021-07-30 06:21 UTC by Konstantin Kolinko
Modified: 2021-07-30 07:41 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kolinko 2021-07-30 06:21:54 UTC
Testing release candidates for Tomcat 9.0.51 and 10.0.9,
the examples web application fails to start when running with Java 8 (8u292).

Trying to access http://localhost:8080/examples/ results in error 404 and in an NullPointerException in a log file.


The error goes away if I use Java 11 (11.0.11) or Java 16 (16.0.1).

Stacktrace for Tomcat 10.0.9 is the following:

org.apache.catalina.startup.HostConfig.deployDirectory Error deploying
web application directory [C:\Program Files\Apache Software
Foundation\Tomcat 10.0\webapps\examples]
    java.lang.IllegalStateException: Error starting child
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
        [... - well-known, skipping]
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
        ... 37 more
    Caused by: java.lang.NullPointerException
        at websocket.ExamplesConfig.getAnnotatedEndpointClasses(ExamplesConfig.java:60)
        at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:111)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5168)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        ... 38 more

Source code of ExamplesConfig:
Comment 1 Remy Maucherat 2021-07-30 06:46:44 UTC
I did build with Java 8.

With Java 8 in that case, we have Class.getPacakge() that returns null (!). With Java 11 it is not null, so it does not fail. The Class.getName() value is fine (websocket.echo.EchoAnnotation in that case).

I don't see what there is to fix here, so far ...
Comment 2 Mark Thomas 2021-07-30 06:55:46 UTC
It looks like some Java 11 stuff got back-ported that shouldn't have. Not sure how I managed that...
Comment 3 Mark Thomas 2021-07-30 06:57:42 UTC
Scratch that. The Eclipse IDE UI is being unhelpful. It was showing the 10.1.x branch history when I was working with 10.0.x.
Comment 4 Remy Maucherat 2021-07-30 07:06:55 UTC
Ok, this is caused by d873f31ca0f64ba1f8c757b6e123196c3bc3de77 which apparently only changes something for Java 8 [no idea why]. If the packages aren't defined in the CL than it's normal that getPackage returns null and that explians the behavior.
Comment 5 Mark Thomas 2021-07-30 07:09:58 UTC
I had just reached the same conclusion.

That changes was not intended to change the logic. Looking now...
Comment 6 Mark Thomas 2021-07-30 07:11:04 UTC
I see this issue. Will have a fix shortly...