Above throws NullPointer at getIdentityLinks in TaskEntity.
java.lang.NullPointerException at org.activiti.engine.impl.persistence.entity.TaskEntity.getIdentityLinks(TaskEntity.java:449) at org.activiti.engine.impl.persistence.entity.TaskEntity.getCandidates(TaskEntity.java:391)
You can retrieve the identity links via the task service getIdentityLinksForTask method. Your example is not the supported way to retrieve candidates or identity links.
To get the candidates defined in the process definition, the easiest way is to use to getBpmnModel method on the RepositoryService interface. It will give back a Java POJO model of the process definition and you can lookup the user task and assignment definition.