Index: modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java =================================================================== --- modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java (revision 6661) +++ modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java (working copy) @@ -49,6 +49,9 @@ EnvironmentImpl environment = EnvironmentImpl.getCurrent(); DbSession dbSession = environment.get(DbSession.class); TaskImpl task = dbSession.findTaskByExecution(execution); + if (task.getAssignee() == null) { + return; + } // make task available to mail templates through task context TaskContext taskContext = new TaskContext(task); Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java (revision 6661) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java (working copy) @@ -145,7 +145,11 @@ } private String[] tokenizeActors(String recipients, Execution execution) { - String[] actors = evaluateExpression(recipients).split("[,;\\s]+"); + String value = evaluateExpression(recipients); + if (value == null) { + throw new JbpmException("cannot find recipients [" + recipients + "] from execution [" + execution + "]"); + } + String[] actors = value.split("[,;\\s]+"); if (actors.length == 0) throw new JbpmException("recipient list is empty: " + recipients); return actors; } Index: modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java (revision 6661) +++ modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java (working copy) @@ -4,22 +4,36 @@ import java.util.*; import javax.mail.Message; +import junit.framework.Test; + import org.jbpm.api.*; import org.jbpm.api.job.*; import org.jbpm.api.task.*; import org.jbpm.pvm.internal.email.spi.*; import org.jbpm.test.*; +import org.jbpm.test.mail.MailTestSetup; +import org.subethamail.wiser.Wiser; +import org.subethamail.wiser.WiserMessage; + /** * @author Huisheng Xu */ public class NotificationTest extends JbpmTestCase { + + private static Wiser wiser = new Wiser(); + + public static Test suite() { + return new MailTestSetup(NotificationTest.class, wiser); + } + protected void setUp() throws Exception { super.setUp(); identityService.createUser("johnsmith", "johnsmith", "johnsmith"); } protected void tearDown() throws Exception { + wiser.getMessages().clear(); identityService.deleteUser("johnsmith"); super.tearDown(); } @@ -72,7 +86,7 @@ public void testSupportExpr() { deployJpdlXmlString( - "" + "" + " " + " " + " " @@ -91,6 +105,31 @@ String processInstanceId = processInstance.getId(); } + public void testNullAssigneeNotification() { + deployJpdlXmlString( + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""); + + ProcessInstance processInstance = executionService + .startProcessInstanceByKey("NullAssigneeNotification"); + String processInstanceId = processInstance.getId(); + + Task task = taskService.createTaskQuery().uniqueResult(); + try { + taskService.assignTask(task.getId(), null); + } catch(JbpmException ex) { + assertEquals("cannot find recipients [${task.assignee}] from execution [execution[" + processInstanceId + "]]", ex.getMessage()); + } + } + public static class JbpmCustomMailProducer implements MailProducer, Serializable { private String templateName; public Collection produce(Execution execution) {