Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null #15991

Closed
iSE-Timur-Ugurlu opened this issue Feb 22, 2023 · 26 comments

Comments

@iSE-Timur-Ugurlu
Copy link

iSE-Timur-Ugurlu commented Feb 22, 2023

Description of the bug

So I am not exactly sure if it is a bug or not but I am struggling with updating Vaadin 8 to Vaadin 23.
I already contacted your Discord Support but had no luck.

We are using Vaadin 8 which we customized a lot to have the expected user experience.

Our environment is: Gradle 7 (latest), Java 17, embedded Jetty 10.0.12, Vaadin 8 (want to upgrade to 23)

To have a little inside in our project:

  • We have our own "navigation", so no Routing in any way. We are always switching Views with the UI dynamically, so we never load/navigate to new Routes.
  • Thats why we extended our CustomUI to the Vaadin UI Class and registered our own Custom Servlet in Vaadin 8
  • We also have our own WebServer based on Jetty 10.

Updating to Vaadin 23

  • We switched our CustomUI to a Div implementation and we are trying to get the same behaviour we need.
    But now we are getting this error you see below and I have no idea why this happens. I try to register the servlet correctly but I thinks its not correct.

I already got a sample project for Vaadin Boot from one of Vaadin Support Members but I had no luck to implement the same behaviour.

If I try to launch our Web Application i get this error:

HTTP ERROR 500 java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null

URI: /
500
java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null
package.CustomUI$Servlet-1eead9be
java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null

Caused by:

java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null
	at com.vaadin.flow.server.VaadinServlet.serveStaticOrWebJarRequest(VaadinServlet.java:401)
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:356)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
	at org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:170)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1383)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1305)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.Server.handle(Server.java:563)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:933)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1077)
	at java.base/java.lang.Thread.run(Unknown Source)

Expected behavior

A view should be shown

Minimal reproducible example

None, our project is too complex to share some example

Versions

  • Vaadin / Flow version: 23.2.*
  • Java version: 17
  • OS version: Win10
  • Browser version (if applicable): latest Chrome
  • Application Server (if applicable): Jetty 10.0.12
  • IDE (if applicable): Eclipse
@Artur-
Copy link
Member

Artur- commented Feb 22, 2023

Possibly your embedded Jetty is not correctly configured to invoke all registered listeners like servletcontextlisteners

@iSE-Timur-Ugurlu
Copy link
Author

Possibly your embedded Jetty is not correctly configured to invoke all registered listeners like servletcontextlisteners

Okey thanks for the reply, I will check out if I can fix this problem 👍

@czp13
Copy link
Contributor

czp13 commented Mar 23, 2023

Related conversations/tickets:

Discord:

Expertise:

No solution yet in these places yet.

Anyone here?
Maybe @TimurUgurlu could you share maybe a minimal product please to reproduce this issue?
Or were you able to find a solution to your problem? Sharing the solution can also work, I could forward it and investigate it in the case of other customers! Thank you in advance 🙏

@iSE-Timur-Ugurlu
Copy link
Author

I have no solution yet, I tried to recreate the VaadinBoot Server Init but had no luck. The same error remains.

I will check if I am allowed to make a small project where the error still appears.

@czp13
Copy link
Contributor

czp13 commented Mar 23, 2023

@TimurUgurlu Thanks for your prompt reply. This issue is tricky, so far I did not see or be aware of any solutions for the affected (not many fortunately, but still a problem for 2-5 I know) customers. A small (GitHub) project, where the issue can be reproduced would be more than helpful! 🙏

@iSE-Timur-Ugurlu
Copy link
Author

iSE-Timur-Ugurlu commented Mar 23, 2023

Maybe the following will bring the issue a step further to fixing the issue:

Somehow I managed to load Vaadin with "no errors" using VaadinBoot with AppShell Class and Main Class with standard Vaadin Servlet.

I get the following error
VaadinError

I took a sample Class from Vaadin Homepage and added an empty Route but it is not registered.

I think it is a classpath error now? It can load all the Vaadin Stuff but not the actual Views?

Found this old thread on Vaadin Forums that has the same problem with Flow but the fix in the last answer didn't work:

https://vaadin.com/forum/thread/18241436/problem-getting-vaadin-flow-to-work-from-embedded-jetty-and-gradle

EDIT: Running from Eclipse gtse me the Route error, running "gradlew run" in cmd gets me staticFileHandler error

I really dont know what is going on

@czp13
Copy link
Contributor

czp13 commented Mar 24, 2023

Hey,
Thanks for moving this further.

It is not clear to me, whether you used VaadinBoot fully, or you added some customer servlet to your project, or you try to combine your project with VaadinBoot. If you could upload your project somewhere, I think more ppl could look into it, it would be super helpful.

Also, the solution in the forum is for V14 and you have the issue for V23, so it can cause that it is not working :(

@johannest
Copy link
Contributor

I tried to reproduce the issue with this sample project using Gradle, V23, and the embedded Jetty, but the project worked fine. Can you try my project and suggest changes to it such that the issue will reproduce? https://github.com/johannest/vaadin-embedded-jetty-gradle-v23

@iSE-Timur-Ugurlu
Copy link
Author

iSE-Timur-Ugurlu commented Mar 27, 2023

Well I have some problems with your repo because there are some problems with multiple jars.
I think some of the dependencies in the build.gradle file use the same and gradle cant decide which to use?

Opening localhost:8080 gives me a 404 Not Found error

Opening analytics page gives me following error:
image

What the console ouputs:
`

d:\dev_home\git\vaadin-embedded-jetty-gradle-v23>gradlew run

Task :vaadinPrepareFrontend

Task :run
/webapp/ROOT is file:/D:/dev_home/git/vaadin-embedded-jetty-gradle-v23/build/resources/main/webapp/ROOT
WebRoot is file:/D:/dev_home/git/vaadin-embedded-jetty-gradle-v23/build/resources/main/webapp
[main] INFO org.eclipse.jetty.server.Server - jetty-10.0.14; built: 2023-02-22T23:12:32.272Z; git: 976721d0f3e903a243584d47870ad2f2c1bf9e55; jvm 17.0.3+6-LTS
[qtp909295153-27] WARN org.eclipse.jetty.annotations.AnnotationParser - javax.xml.bind.Binder scanned from multiple locations: jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jboss.spec.javax.xml.bind/jboss-jaxb-api_2.3_spec/2.0.1.Final/b3bfc1618b2f4b2c6aa11350df4aefb4dfe6856/jboss-jaxb-api_2.3_spec-2.0.1.Final.jar!/javax/xml/bind/Binder.class, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/jakarta.xml.bind/jakarta.xml.bind-api/2.3.3/48e3b9cfc10752fba3521d6511f4165bea951801/jakarta.xml.bind-api-2.3.3.jar!/javax/xml/bind/Binder.class
[qtp909295153-27] WARN org.eclipse.jetty.annotations.AnnotationParser - javax.xml.bind.ContextFinder$1 scanned from multiple locations: jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jboss.spec.javax.xml.bind/jboss-jaxb-api_2.3_spec/2.0.1.Final/b3bfc1618b2f4b2c6aa11350df4aefb4dfe6856/jboss-jaxb-api_2.3_spec-2.0.1.Final.jar!/javax/xml/bind/ContextFinder$1.class, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/jakarta.xml.bind/jakarta.xml.bind-api/2.3.3/48e3b9cfc10752fba3521d6511f4165bea951801/jakarta.xml.bind-api-2.3.3.jar!/javax/xml/bind/ContextFinder$1.class
[qtp909295153-27] WARN org.eclipse.jetty.annotations.AnnotationParser - javax.xml.bind.ContextFinder$2 scanned from multiple locations: jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jboss.spec.javax.xml.bind/jboss-jaxb-api_2.3_spec/2.0.1.Final/b3bfc1618b2f4b2c6aa11350df4aefb4dfe6856/jboss-jaxb-api_2.3_spec-2.0.1.Final.jar!/javax/xml/bind/ContextFinder$2.class, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/jakarta.xml.bind/jakarta.xml.bind-api/2.3.3/48e3b9cfc10752fba3521d6511f4165bea951801/jakarta.xml.bind-api-2.3.3.jar!/javax/xml/bind/ContextFinder$2.class

[many more]

[main] INFO org.eclipse.jetty.webapp.StandardDescriptorProcessor - NO JSP Support for /analytics, did not find org.eclipse.jetty.jsp.JettyJspServlet
[main] INFO org.eclipse.jetty.server.handler.ContextHandler.analytics - Initializing AtmosphereFramework
[main] INFO org.eclipse.jetty.server.session.DefaultSessionIdManager - Session workerName=node0
[main] INFO com.vaadin.flow.server.startup.ServletDeployer - Skipping automatic servlet registration because there is already a Vaadin servlet with the name com.vaadin.flow.server.VaadinServlet-5f341870
Mõrz 27, 2023 6:49:14 PM org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap createDeployment
WARN: RESTEASY002150: resteasy.scan is no longer supported. Use a servlet 3.0 container and the ResteasyServletInitializer
Mõrz 27, 2023 6:49:14 PM org.jboss.resteasy.spi.ResteasyDeployment processApplication
INFO: RESTEASY002225: Deploying javax.ws.rs.core.Application: class com.vaadin.starter.skeleton.AnalyticsRSApplication
Mõrz 27, 2023 6:49:14 PM org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap createDeployment
WARN: RESTEASY002150: resteasy.scan is no longer supported. Use a servlet 3.0 container and the ResteasyServletInitializer
Mõrz 27, 2023 6:49:14 PM org.jboss.resteasy.spi.ResteasyDeployment processApplication
INFO: RESTEASY002225: Deploying javax.ws.rs.core.Application: class com.vaadin.starter.skeleton.RenderRSApplication
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.w.WebAppContext@2accdbb5{/analytics,[file:///D:/dev_home/git/vaadin-embedded-jetty-gradle-v23/build/resources/main/webapp/, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-lumo-theme/23.3.6/18fd17b72501e465b04aa55558dd89fbdabc7e34/vaadin-lumo-theme-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-iron-list-flow/23.3.6/a75d74926642bd44889ab16ccdc9e81cb18df9d3/vaadin-iron-list-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-notification-flow/23.3.6/8c597c0dfa1329ceff4bbe890e504f97e9cb5e56/vaadin-notification-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-combo-box-flow/23.3.6/9100b73573c6e8a78a5d76c1db65e2a7e39ece24/vaadin-combo-box-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-virtual-list-flow/23.3.6/8073e82277fc3373e8cd69ea6f07686b9cb310ff/vaadin-virtual-list-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-context-menu-flow/23.3.6/7c3bd54f905ba3abb6b90ebe45b482511df63d28/vaadin-context-menu-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-select-flow/23.3.6/4980f538120d0d6c31cf6d84ff618037e92c0491/vaadin-select-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-menu-bar-flow/23.3.6/ebd287801986a0d2aaa28538b68a3e48e306ca1a/vaadin-menu-bar-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-messages-flow/23.3.6/f414daec424b8d25cade110bbb24d00d55fec5da/vaadin-messages-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-material-theme/23.3.6/aa60df5a18ff4dcaa99829f492ce3c28fd48b6ff/vaadin-material-theme-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-time-picker-flow/23.3.6/105168e32f34a5767f76965c044ad020f2ae3563/vaadin-time-picker-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-dialog-flow/23.3.6/1bb5639cd63ffcaa0c353a288c9dc2a87310b2bf/vaadin-dialog-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/org.webjars.npm/mobile-drag-drop/2.3.0-rc.2/5a95a71ecc9e41b2253b80badc1ad0a9b8f3b7a4/mobile-drag-drop-2.3.0-rc.2.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-renderer-flow/23.3.6/65d1fe85ce9c38a52cd6fad4acdea0eb8cd80cb8/vaadin-renderer-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/org.webjars.npm/vaadin__vaadin-mobile-drag-drop/1.0.1/57cea9e7d3c1f5cebaa8c2e99b07c9bdc734878e/vaadin__vaadin-mobile-drag-drop-1.0.1.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-grid-flow/23.3.6/16554e4a1a789bc3d2c1dd5d3682adda5e6a1ecf/vaadin-grid-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-confirm-dialog-flow/23.3.6/41bdc7fd02fe21278f8e5d2cac0ab69888451e30/vaadin-confirm-dialog-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-login-flow/23.3.6/530e8c319da84b78c1034226e3d1ab2168d328e8/vaadin-login-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-flow-components-base/23.3.6/fc99199f92979ada2e90cc836d0ad7805a4a19a/vaadin-flow-components-base-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/flow-push/23.3.4/65fe1b668120ca40974e55cff81258f6167d45a0/flow-push-23.3.4.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/flow-client/23.3.4/788731154b63e9358b1ae340f3a299edfb38a5a4/flow-client-23.3.4.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-text-field-flow/23.3.6/c2e28397b13cd459d082177a638db5cea1eff8c6/vaadin-text-field-flow-23.3.6.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/flow-dnd/23.3.4/bb54ac08cad8615beaf45752255164391bddbd/flow-dnd-23.3.4.jar!/META-INF/resources, jar:file:///C:/Users/user/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-date-picker-flow/23.3.6/3067fd9fb0e4b653b6b86d9e4057e90ede13d5f7/vaadin-date-picker-flow-23.3.6.jar!/META-INF/resources],AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@5faeada1{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[main] INFO org.eclipse.jetty.server.Server - Started Server@77ec78b9{STARTING}[10.0.14,sto=0] @2423ms
<==========---> 80% EXECUTING [8s]

:run

:run`

@johannest
Copy link
Contributor

@TimurUgurlu if you intended to run the project in dev mode, please set PRODUCTION_MODE = false; in Main.java. Otherwise try build and run the app with the following commands:
./gradlew clean build -Pvaadin.productionMode
./gradlew run
See also the READMEmd file of the project

@iSE-Timur-Ugurlu
Copy link
Author

@TimurUgurlu if you intended to run the project in dev mode, please set PRODUCTION_MODE = false; in Main.java. Otherwise try build and run the app with the following commands: ./gradlew clean build -Pvaadin.productionMode ./gradlew run See also the READMEmd file of the project

Ohh next time I should read the Readme 🤦‍♂️

It worked now. I will try to reproduce the error now, hope it works out somehow.
First I will try a custom Servlet.

@Artur-
Copy link
Member

Artur- commented Mar 30, 2023

I took the default project from start.vaadin.com and converted it from Spring Boot into using an embedded Jetty: https://github.com/Artur-/vaadin24-embedded-jetty

If you leave out the ContainerIncludeJarPattern configuration at

https://github.com/Artur-/vaadin24-embedded-jetty/blob/01659c43109f21e113373840b42743211f821744/src/main/java/com/example/application/Application.java#L34-L36

then you will get

Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null

on startup because the listeners are not found and invoked on startup

@czp13
Copy link
Contributor

czp13 commented Mar 30, 2023

Thank you @Artur- for reproducing it. I came to the same conclusion in the relevant JIRA ticket that this line is super important (with some insights from Martin Vyšný), but could not reproduce it, and shared this solution with the customer, but big lesson JIRA formatted it, and only after I sent push click :S, so it was missing some characters.

Anyway, I got back to the customer to correct my mistake now, and I hope this will solve the original issue for them in their case as well (harder, because we do not have access to their codebase so can only give hints, and ideas).

@czp13 czp13 removed their assignment Apr 2, 2023
@mvysny
Copy link
Member

mvysny commented Apr 5, 2023

The reason for the original NPE is that the LookupServletContainerInitializer was not called, Lookup was not initialized and set, and therefore the staticFileHandler field initialization is skipped in VaadinServlet.init().

To fix this, you have to enable Jetty classpath scanning with the ContainerIncludeJarPattern setting, which then causes Jetty to discover and initialize LookupServletContainerInitializer properly.

Please read more here: https://mvysny.github.io/vaadin-lookup-vs-instantiator/

@mcollovati
Copy link
Collaborator

@TimurUgurlu does set the ContainerIncludeJarPattern property as suggested above, resolve the issue?

@iSE-Timur-Ugurlu
Copy link
Author

iSE-Timur-Ugurlu commented Apr 18, 2023

I am still stuck here:

#15991 (comment)

@mcollovati
Copy link
Collaborator

@TimurUgurlu could you put a breakpoint in RouteRegistryInitializer.initialize and check if it is invoked during server startup?
If the breakpoint is reached, you can inspect the classSet parameter to see if your views are there

@johannest
Copy link
Contributor

johannest commented Jun 5, 2023

@mcollovati Looks like the issue still reproduces when running the app through (fat) jar with dependencies. I forked Artur's project and changed the pom.xml such that it would create a fat jar: https://github.com/johannest/vaadin24-embedded-jetty. When running it: java -jar target/embedded-jetty-1.0-SNAPSHOT-jar-with-dependencies.jar I got the same error as before.

The same issue happens also with Gradle if running the jar directly. However if running it through Gradle distribution's generated shell script it works fine. The Gradle generated shell script creates a java -cp command with an explicit classpath which seems to fix the issue. But, when running directly as java -jar, it looks like Vaadin does not load VaadinAppShellInitializer and thus the Lookup.class is not placed into VaadinContext. That then makes VaadinServlet to skip initializing the static file handler.

@johannest
Copy link
Contributor

johannest commented Jun 13, 2023

Few more comments. We got this working both with Maven project and Gradle project.

  1. Maven project. The key thing was to use maven-shade-plugin with ServicesResourceTransformer. See the example project: https://github.com/johannest/vaadin24-embedded-jetty
  2. Gradle project (and Dockerized example). Similar thing was did there: com.github.johnrengelman.shadow plugin with mergeServiceFiles was used. Example project here: https://github.com/johannest/vaadin-embedded-jetty-gradle-v23

Note! Using these shade/shadow plugins is maybe not the best practice since they basically extract every dependency to root of the jar files which is prone to error. That was actually the principal reason why this failed before: when the fat jar is built the one of dependencies overrides META-INF/service/jakarta.servlet.ServletContainerInitializer and thus Vaadin lookup (SPI) is never initialized. The better way would be using Spring Boot jar or Gradle distribution plugin which keep the dependencies in their own jar files.

I think this ticket can be closed now.

@mcollovati
Copy link
Collaborator

Thanks, @johannest, for the update.
I'll close the ticket.
Please comment here or open a new issue if the problem continues to occur, even applying the above suggestions.

@cliviu
Copy link

cliviu commented Sep 20, 2024

It strikes again :-(

Vaadin: 24.4.11 Jetty 11.0.24

Everything done by the book, as shown in the previous comments

HTTP ERROR 500 java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null STATUS: 500 MESSAGE: java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null SERVLET: com.vaadin.flow.server.VaadinServlet-1aee6983 CAUSED BY: java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null Caused by: java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.StaticFileHandler.serveStaticResource(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)" because "this.staticFileHandler" is null at com.vaadin.flow.server.VaadinServlet.serveStaticOrWebJarRequest(VaadinServlet.java:430) at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:385) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:529) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:598) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1580) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1381) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1553) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1303) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129) at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122) at org.eclipse.jetty.server.Server.handle(Server.java:563) at org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100) at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:558) at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:379) at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:146) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100) at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:421) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:199) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149) at java.base/java.lang.Thread.run(Thread.java:1583) Powered by Jetty:// 11.0.24

It may be something Jetty related because with Jetty 11.0.14 works ...

@mcollovati
Copy link
Collaborator

@cliviu if you can provide a reproducible example, please create a new issue, so that we can better track the problem

@cliviu
Copy link

cliviu commented Sep 23, 2024

Somehow, starting with Jetty 11.0.16 the LookupServletContainerInitializer is not found. Jetty 11.0.15 is the last version where it works. I am not sure where the problem is.
This example works with any Jetty version https://github.com/johannest/vaadin24-embedded-jetty

@cliviu
Copy link

cliviu commented Sep 24, 2024

jetty/jetty.project#12304

@cliviu
Copy link

cliviu commented Sep 25, 2024

Just for the record, if somebody bumps into it : starting with version 11.0.16 websocket-jetty-server does not include the jetty-annotations as dependency. If jetty-annotations are not in the classpath, LookupServletContainerInitializer will not be scanned and we are back to the same issue. So the solution will be to separately include jetty-annotations as dependency starting with jetty 11.0.16. Not a real problem but it fails silently and it can be really nasty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants