VaadinService.getCurrent().getBaseDirectory() Returns Null

I added a @WebFilter to my Vaadin app and its initialization calls VaadinService.getCurrent().getBaseDirectory() to load a config file. This is returning null. The Vaadin docs say this return “base directory”. Is this the webapp’s docBase or something else? Why is it not set?

I think it can be null in some cases. It depends how application is deployed. E.g. if you are running Spring Boot app locally with embedded Tomcat, or something like that.

We are using embedded Tomcat. Is there something we can configure so that it is not null?

Wow, the @WebFilter is preventing Vaadin from working correctly. Lots of NPEs from VaadinService. It seems that Vaadin itself is not initializing properly with a WebFilter defined.

Ok, it seems that I had put our WebFilter in a Jar and put that jar in the Tomcat lib folder because I thought Tomcat needed it in its classpath. That was causing the NPEs in VaadinService, odd. Removing that jar stopped the bloodshed. I’ll bet there is an order of class loading issue with Vaadin and that’s why VaadinService.getCurrent().getBaseDirectory() does not work if the filter class is loaded before Vaadin.