AnsweredAssumed Answered

getRenderedTaskForm Null Pointer Exception for Ad Hoc task

Question asked by aapthorp on May 4, 2012
Latest reply on May 7, 2012 by trademak
When I call formService.getRenderedTaskForm with a task id of a task that just happens to be an ad-hoc task a Null Pointer Exception is thrown in Activiti 5.9. I'm assuming this is a bug but am posting here first. My code:

 public DataHandler getForm() {
    DataHandler dh = null;
    FormService formService = processEngine.getFormService();
    String form = null;
    if ((form = (String)formService.getRenderedTaskForm(task.getId())) != null) {


Stacktrace as follows:

2012-05-02 22:34:44,626 SEVERE [org.activiti.engine.impl.interceptor.CommandContext] (http-localhost%2F127.0.0.1-8080-8) Error while closing command context: java.lang.NullPointerException
   at org.activiti.engine.impl.cmd.GetRenderedTaskFormCmd.execute( [:5.9]
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute( [:5.9]
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute( [:5.9]
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute( [:5.9]
   at org.activiti.engine.impl.FormServiceImpl.getRenderedTaskForm( [:5.9]
   at com.ajita.ical.activiti.actTask.getForm( [:]

Looking at the source of GetRenderedTaskFormCmd it seems that a returned null task definition from getTaskDefinition in org.activiti.engine.impl.persistence.entity.TaskEntity is the likely cause.

    TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler == null) {
      return null;

Presumably ad-hoc tasks have no task definition? I've confirmed this by the db record for the task in question.

My workaround is to check

if (task.getTaskDefinitionKey() !=null) {

first, but I would still expect this to be handled gracefully.