Skip to content

StatisticsStorage.internalRead explodes if usage-statistics.json is empty #13362

Closed

Description

@Legioth

Description of the bug

For some reason, the ~/.vaadin/usage-statistics.json file ended up as empty. I suspect this might have been because of restarting the server at the exact moment when that file was about to be written.

When in this state, logic in StatisticsStorage.internalRead fails because it assumes that the content in the file will be an ObjectNode but it actually gets a com.fasterxml.jackson.databind.node.MissingNode instance instead. The result is that the server cannot start up with this exception:

java.lang.RuntimeException: Unable to initialize com.vaadin.flow.spring.VaadinServletContextInitializer$DevModeServletContextListener
        at com.vaadin.flow.spring.VaadinServletContextInitializer$FailFastServletContextListener.contextInitialized(VaadinServletContextInitializer.java:191) ~[vaadin-spring-23.0.1.jar:na]
        at com.vaadin.flow.spring.VaadinServletContextInitializer$CompositeServletContextListener.lambda$contextInitialized$0(VaadinServletContextInitializer.java:213) ~[vaadin-spring-23.0.1.jar:na]
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) ~[na:na]
        at com.vaadin.flow.spring.VaadinServletContextInitializer$CompositeServletContextListener.contextInitialized(VaadinServletContextInitializer.java:213) ~[vaadin-spring-23.0.1.jar:na]
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4766) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:478) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.16.jar:5.3.16]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar:2.6.4]
        at com.example.application.Application.main(Application.java:25) ~[classes/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.4.jar:2.6.4]
Caused by: java.lang.ClassCastException: class com.fasterxml.jackson.databind.node.MissingNode cannot be cast to class com.fasterxml.jackson.databind.node.ObjectNode (com.fasterxml.jackson.databind.node.MissingNode and com.fasterxml.jackson.databind.node.ObjectNode are in unnamed module of loader 'app')
        at com.vaadin.base.devserver.stats.StatisticsStorage.internalRead(StatisticsStorage.java:149) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.StatisticsStorage.lambda$update$f902d37c$1(StatisticsStorage.java:93) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.StatisticsStorage.access(StatisticsStorage.java:80) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.StatisticsStorage.update(StatisticsStorage.java:92) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.DevModeUsageStatistics.trackGlobalData(DevModeUsageStatistics.java:106) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.DevModeUsageStatistics.lambda$init$30ce3648$1(DevModeUsageStatistics.java:98) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.StatisticsStorage.access(StatisticsStorage.java:80) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.stats.DevModeUsageStatistics.init(DevModeUsageStatistics.java:89) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.startup.DevModeInitializer.initDevModeHandler(DevModeInitializer.java:217) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.base.devserver.DevModeHandlerManagerImpl.initDevModeHandler(DevModeHandlerManagerImpl.java:80) ~[vaadin-dev-server-23.0.2.jar:na]
        at com.vaadin.flow.spring.VaadinServletContextInitializer$DevModeServletContextListener.failFastContextInitialized(VaadinServletContextInitializer.java:474) ~[vaadin-spring-23.0.1.jar:na]
        at com.vaadin.flow.spring.VaadinServletContextInitializer$FailFastServletContextListener.contextInitialized(VaadinServletContextInitializer.java:187) ~[vaadin-spring-23.0.1.jar:na]
        ... 46 common frames omitted

Expected behavior

  1. This case should be resolved gracefully
  2. Usage statistics errors in general should not cause server startup to be broken

Minimal reproducible example

  1. Create an empty ~/.vaadin/usage-statistics.json
  2. Start a Vaadin application

Versions

  • Vaadin / Flow version: 23.0.1

Activity

  1. added a commit that references this issue on Mar 25, 2022
    b0573a8
  2. added a commit that references this issue on Mar 28, 2022
    09190fd
  3. added 4 commits that reference this issue on Mar 28, 2022
    9cdbc39
    d11147d
    c0a3f82
    fdf901e
  4. vaadin-bot commented on Apr 5, 2022

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 22.0.12.

  5. vaadin-bot commented on Apr 5, 2022

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 23.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions