Got a null pointer exception when building the engine

Hi,

We just migrated from Activiti 5.x to Camunda 7.6.0 successfully. Now, we are trying to move to a bigger version and everything goes smoothly 'til version 7.11.0. Trying to move to 7.12.0 causes an exception. A process that was running ok, throws now a NullPointerException in line 47 of SpringBeansResolverFactory:

String[] beannames = applicationContext.getBeanDefinitionNames();

The error clearly shows that for some reason applicationContext is null.

By debugging we found that this code is called when initScripting() is being executed.

Here, an excerpt of the actual stack trace:

Caused by: java.lang.NullPointerException: null
	at org.camunda.bpm.engine.spring.SpringBeansResolverFactory.<init>(SpringBeansResolverFactory.java:47)
	at org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration.initScripting(SpringProcessEngineConfiguration.java:47)
	at org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:836)
	at org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:814)
	at org.camunda.bpm.engine.spring.SpringTransactionsProcessEngineConfiguration.buildProcessEngine(SpringTransactionsProcessEngineConfiguration.java:63)

Our project uses Spring Boot 2.2.0 and runs against a Postgres DB. In this particular issue we can see that the db has not been touched yet for it is happening at the very early stages of the engine initiation.

Thanks.

Have you checked out the compatibility matrix to ensure that you’re using the right spring boot version with the the right engine version.

Yes. Actually we saw in the documentation for migration that checking that compatibility is a requirement when using Camunda Spring Starter. Even if we are not using it, we made sure we are using Spring Boot 2.2.0, which is the requirement in the matrix. Thanks.

I decided to create a simple project to illustrate the issue. You may clone https://github.com/hernandezjd/camunda-example.git.

And run

./gradlew test

Everything should be ok and the one single test in the project should pass.

Then, if you go to build.gradle and change the version of Camunda from 7.11 to 7.12 and try again the test, you will get the error cause by the NullPointerException already described.

The project is a simple Java project that intends to be a library that uses a Camunda engine. The one single test just tries to inject the engine service and verifies it is available (not null):

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = TestConfiguration.class)
public class TestEngineService {

	@Autowired
	private EngineService engineService;

	@Test
	public final void testThatEngineServiceIsAvailable() {
		assertNotNull(engineService);
	}
}

EngineService is defined using a simple Spring service like this:

@Service
public class EngineService {

	public EngineService(ProcessEngineFactoryBean processEngineFactoryBean) {
		processEngineFactoryBean.getProcessEngineConfiguration().buildProcessEngine();
	}
}

And the process engine configuration is pretty much the one written in all documentation and getting started manuals from Camunda:

@Configuration
public class EngineConfiguration {

	private DataSource dataSource() {

		SimpleDriverDataSource dataSource = new SimpleDriverDataSource();

		dataSource.setDriverClass(org.h2.Driver.class);
		dataSource.setUrl("jdbc:h2:mem:camunda;DB_CLOSE_DELAY=-1");
		dataSource.setUsername("sa");
		dataSource.setPassword("");

		return dataSource;
	}

	private DataSourceTransactionManager transactionManager() {

		return new DataSourceTransactionManager(dataSource());
	}

	private SpringProcessEngineConfiguration processEngineConfiguration() {

		SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();

		config.setDataSource(dataSource());
		config.setTransactionManager(transactionManager());

		config.setDatabaseSchemaUpdate("true");
		config.setHistory("audit");
		config.setJobExecutorActivate(true);

		return config;
	}

	@Bean
	public ProcessEngineFactoryBean processEngineFactoryBean() {

		ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
		factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
		return factoryBean;
	}

}

This is the original build.gradle file, before switching to 7.12:


plugins {
	id 'java'
	id "io.spring.dependency-management" version "1.0.9.RELEASE"
}

sourceCompatibility = '1.8'

ext {
	camunda_version = '7.11.0'
	spring_version = '5.2.11.RELEASE'
}

dependencyManagement {
	
	imports {
			mavenBom "org.camunda.bpm:camunda-bom:${camunda_version}"
			mavenBom "org.springframework:spring-framework-bom:${spring_version}"
	}
}
	
dependencies {

	repositories {
		mavenCentral() 
	}
	
	compile (group: 'org.camunda.bpm', name: 'camunda-engine')
	compile (group: 'org.camunda.bpm', name: 'camunda-engine-spring')

	compile (group: 'org.springframework', name: 'spring-context')
	compile (group: 'org.springframework', name: 'spring-jdbc')
	compile (group: 'org.springframework', name: 'spring-tx')
	compile (group: 'org.springframework', name: 'spring-orm')

	compile (group: 'com.h2database', name: 'h2', version: '1.4.196')
	
	testCompile (group: 'junit', name: 'junit', version: '4.12')
	testCompile (group: 'org.springframework', name: 'spring-test')

}

Any help for troubleshooting this issue will be much appreciated.

Thanks.

1 Like