Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-11989

Null pointer exception in JobExecutorHealthIndicator

    • Icon: Bug Report Bug Report
    • Resolution: Fixed
    • Icon: L3 - Default L3 - Default
    • None
    • 7.13.0
    • spring-boot
    • None

      Hi,

      I've encountered the issue described here: https://forum.camunda.org/t/jobexecutorhealthindicator-health-check-failed-java-lang-nullpointerexception-null/16312

      java.lang.NullPointerException: null
      	at java.base/java.util.HashSet.<init>(HashSet.java:119) ~[na:na]
      	at org.camunda.bpm.spring.boot.starter.actuator.JobExecutorHealthIndicator$Details.<init>(JobExecutorHealthIndicator.java:65) ~[camunda-bpm-spring-boot-starter-7.13.0.jar:7.13.0]
      

       

      The cause seems to be that SpringJobExecutor gets injected into:

      https://github.com/camunda/camunda-bpm-spring-boot-starter/blob/master/starter/src/main/java/org/camunda/bpm/spring/boot/starter/CamundaBpmActuatorConfiguration.java#L41

      however we are using the DefaultJobExecutor in our process engine.

      Reproducer code: https://github.com/andrejs-j/camunda-bpm-examples/pull/1/files

       

        This is the controller panel for Smart Panels app

            [CAM-11989] Null pointer exception in JobExecutorHealthIndicator

            andrejs,

            Thanks for raising this bug report. I was able to reproduce the bug via this test. I will investigate further.

            Cheers,
            Miklas

            Miklas Boskamp added a comment - andrejs , Thanks for raising this bug report. I was able to reproduce the bug via this test . I will investigate further. Cheers, Miklas

            Hey andrejs (cc thorben.lindhauer),

            I investigated a bit and I think I have a good understanding of what is causing the issue for you.

            In the example code you shared, you are creating a custom ProcessEngineConfiguration. Note, that the SpringProcessEngineConfiguration creates a new DefaultJobExecutor (see) which is not provided as Spring Boot Bean. Since there is no JobExecutor available as Spring Boot Bean, a SpringJobExecutor is created. However, the process engine is not registered for this JobExecutor causing the NPE during the health check.

            This issue does not occur when using the default process engine configuration. If you want to provide your own, you should also make sure to register all process engine plugins like it is done in the default case. One of the plugins is the DefaultJobConfiguration which provides the JobExecutor Bean.

            When I change your code to something like the following all process engine plugins are registered and the JobExecutor is provided as Bean:

              @Bean
              public SpringProcessEngineConfiguration engineConfiguration(List<ProcessEnginePlugin> processEnginePlugins, DataSource dataSource,
                  PlatformTransactionManager transactionManager) {
                SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
                configuration.setDataSource(dataSource);
                configuration.setTransactionManager(transactionManager);
                configuration.setJobExecutorActivate(true);
                configuration.setDatabaseSchemaUpdate("true");
                configuration.getProcessEnginePlugins().add(new CompositeProcessEnginePlugin(processEnginePlugins));
                return configuration;
              }
            

            That said, I would not consider this a bug anymore. I would agree though, that the NPE should be avoided. Maybe by making sure that only one JobExecutor can be created.

            Miklas Boskamp added a comment - Hey andrejs (cc thorben.lindhauer ), I investigated a bit and I think I have a good understanding of what is causing the issue for you. In the example code you shared, you are creating a custom ProcessEngineConfiguration. Note, that the SpringProcessEngineConfiguration creates a new DefaultJobExecutor ( see ) which is not provided as Spring Boot Bean. Since there is no JobExecutor available as Spring Boot Bean, a SpringJobExecutor is created . However, the process engine is not registered for this JobExecutor causing the NPE during the health check. This issue does not occur when using the default process engine configuration. If you want to provide your own, you should also make sure to register all process engine plugins like it is done in the default case . One of the plugins is the DefaultJobConfiguration which provides the JobExecutor Bean. When I change your code to something like the following all process engine plugins are registered and the JobExecutor is provided as Bean: @Bean public SpringProcessEngineConfiguration engineConfiguration(List<ProcessEnginePlugin> processEnginePlugins, DataSource dataSource, PlatformTransactionManager transactionManager) { SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration(); configuration.setDataSource(dataSource); configuration.setTransactionManager(transactionManager); configuration.setJobExecutorActivate( true ); configuration.setDatabaseSchemaUpdate( " true " ); configuration.getProcessEnginePlugins().add( new CompositeProcessEnginePlugin(processEnginePlugins)); return configuration; } That said, I would not consider this a bug anymore. I would agree though, that the NPE should be avoided. Maybe by making sure that only one JobExecutor can be created.

            Andrejs added a comment -

            Hi Miklas,

             

            Thank you for the suggestion! Can confirm that it fixes the issue in our app code as well.

            I guess it is a bit confusing that two executors are created and we only use one. Perhaps the executor that is used should be exposed as a bean, not sure.

             

             

            Andrejs added a comment - Hi Miklas,   Thank you for the suggestion! Can confirm that it fixes the issue in our app code as well. I guess it is a bit confusing that two executors are created and we only use one. Perhaps the executor that is used should be exposed as a bean, not sure.    

            andrejs, I am glad that it works for you now. As I said this only happens because of the misconfiguration. Usually, when only one JobExecutor is created (like it should) it will be exposed as Bean.

            Miklas Boskamp added a comment - andrejs , I am glad that it works for you now. As I said this only happens because of the misconfiguration. Usually, when only one JobExecutor is created (like it should) it will be exposed as Bean.

            Andrejs added a comment -

            Fair enough, I think I was trying to follow the configuration example in: https://github.com/camunda/camunda-bpm-examples/tree/master/deployment/spring-boot#configure-the-process-engine

             

            Andrejs added a comment - Fair enough, I think I was trying to follow the configuration example in:  https://github.com/camunda/camunda-bpm-examples/tree/master/deployment/spring-boot#configure-the-process-engine  

            Thanks for your insight andrejs, I created CAM-12028 to improve the documentation and examples to include our findings.

            I will close this ticket, but if you have more information on the topic or think that something should be addressed code-wise, feel free to comment again or re-open the ticket and I will be happy to discuss it with you.

            Have a nice weekend

            Miklas Boskamp added a comment - Thanks for your insight andrejs , I created CAM-12028 to improve the documentation and examples to include our findings. I will close this ticket, but if you have more information on the topic or think that something should be addressed code-wise, feel free to comment again or re-open the ticket and I will be happy to discuss it with you. Have a nice weekend

              miklas.boskamp Miklas Boskamp
              andrejs Andrejs
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: