Hi, I use repositoryService to retrieve list of process definitions, convert the results to JSON response and return to browser. Here is code snippet:
@RequestMapping(value = "/rest/process-definitions", method = RequestMethod.GET, produces = "application/json")
public List<ProcessDefinition> findProcessDefinitions(@RequestParam Map<String, String> allRequestParams) {
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
...
List<ProcessDefinition> data = processDefinitionQuery.listPage(0, 10);
return data;
}
The code above runs normally. However, Spring throws NullPointerException while converting the results to JSON:
org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: (was java.lang.NullPointerException) (through reference chain: java.util.HashMap[“rows”]->java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl[“identityLinks”]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.HashMap[“rows”]->java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl[“identityLinks”])
I digged into the source and found that there is getIdentityLinks() method in ProcessDefinitionEntityImpl class, as follows:[code] public List getIdentityLinks() {
if (!isIdentityLinksInitialized) {
definitionIdentityLinkEntities = Context.getCommandContext().getIdentityLinkEntityManager().findIdentityLinksByProcessDefinitionId(id);
isIdentityLinksInitialized = true;
}
return definitionIdentityLinkEntities;
}
[/code]
Since Context.getCommandContext() returns null here, NullPointerException is thrown.
Question: how could this NullPointerException be avoided? Or if I missed some configuration?
Here is my configuration:[code]
<!-- Checks the version of the flowable DB schema and throws an exception if the versions don’t match -->
<property name="databaseSchemaUpdate" value ="false" />
[/code]