Using TaskService in User Task Complete Listener

I’m trying to get the candidate groups from a task in the task complete listener. I’m using the following code to get the identity links and then filter out the candidate groups:

public void notify(DelegateTask delegateTask) {
...
List<IdentityLink> candidates = delegateTask.getProcessEngine().getTaskService().getIdentityLinksForTask(delegateTask.getId());
...
}

But this throws a null pointer exception during the process end. Is there a reason for this?

I know that I can get the identity links for the task directly from the task delegate, but I am trying to use some common APIs we have that use just the taskId that we may have acquired from a task query.

Set<IdentityLink> candidates = delegateTask.task.getCandidates();

That call works without exception and is currently our workaround, but I would prefer to have one code path.

I appreciate any help or explanation.

Hi @john.caridi,

Execute the below query in db directly and check whether the query returns the result or not. Replace the placeholder with actual taskid in the query.

select * from ACT_RU_IDENTITYLINK where TASK_ID_ = '< taskid >';

List<IdentityLink> candidates = delegateTask.getProcessEngine().getTaskService().getIdentityLinksForTask(delegateTask.getId());

Size of the candidates is 0? candidates.size==0 ?

In api call, what exception are you getting. can you provide the complete stack trace of the exception?

Here is some more information: I am using the java api to complete this task:

ProcessEngine camundaProcessEngine;
...
Task ti = camundaProcessEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
camundaProcessEngine.getTaskService().complete(ti.getId());

I added the following to my task complete listener:

public void notify(DelegateTask delegateTask) {

    List<IdentityLink> candidates = delegateTask.getProcessEngine().getTaskService().getIdentityLinksForTask(delegateTask.getId());
    log.info("Size of candidates: " + candidates.size());

} 

The log output gives me:

(TaskCompletedListener):Size of candidates: 2

So everything seems to work as expected, but it looks like later something is trying to be persisted for this task to the database before the complete returns but after it was completed. Here is the stack trace from the exception:

java.lang.NullPointerException
java.lang.String.compareTo(String.java:1143)
org.camunda.bpm.engine.impl.db.entitymanager.operation.comparator.DbEntityOperationComparator.compare(DbEntityOperationComparator.java:39)
org.camunda.bpm.engine.impl.db.entitymanager.operation.comparator.DbEntityOperationComparator.compare(DbEntityOperationComparator.java:28)
java.util.TreeMap.put(TreeMap.java:552)
java.util.TreeSet.add(TreeSet.java:255)
org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperationManager.addOperation(DbOperationManager.java:80)
org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.performEntityOperation(DbEntityManager.java:587)
org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushCachedEntity(DbEntityManager.java:465)
org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushEntityCache(DbEntityManager.java:431)
org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:291)
org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:263)
org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:186)
org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:119)
org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70)
org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
org.camunda.bpm.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:179)
org.camunda.bpm.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:175)
com.olf.bpm.engine.camunda.commands.TaskCompleteCommand.processTaskComplete(TaskCompleteCommand.java:443)
com.olf.bpm.engine.camunda.commands.TaskCompleteCommand.process(TaskCompleteCommand.java:209)
com.olf.bpm.adaptors.camunda.CamundaAdaptor.process(CamundaAdaptor.java:188)
com.olf.bpm.ProcessCommand.process(ProcessCommand.java:118)
com.olf.bpm.ProcessCommand.run(ProcessCommand.java:81)