cancel
Showing results for 
Search instead for 
Did you mean: 

Why run Context.getCommandContex cause NullPointerException

kafeitu
Champ on-the-rise
Champ on-the-rise
these codes in method of Struts2 Action

TaskQuery taskQuery = taskService.createTaskQuery().processDefinitionKey("leave").taskCandidateUser(UserUtil.getCurrentUserId());
List<Task> tasks = taskQuery.listPage(0, 10);
for (Task task : tasks) {
   TaskEntity taskEntity = (TaskEntity) task;
   System.out.println(taskEntity.getIdentityLinks());
}

in applicationContext.xml:

<!– activiti begin –>
   <bean id="jdbcTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
   </bean>

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="jdbcTransactionManager" />
      <property name="databaseSchemaUpdate" value="false" />
      <property name="jobExecutorActivate" value="false" />
      <property name="deploymentResources" value="classpath*:/com/wsria/demo/activiti/*.bpmn20.xml"></property>
   </bean>

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

   <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
   <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
   <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
   <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
   <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
   <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
   <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
   <!– activiti end –>

java.lang.NullPointerException
   at org.activiti.engine.impl.persistence.entity.TaskEntity.getIdentityLinks(TaskEntity.java:342)
   at com.wsria.demo.activiti.web.oa.leave.LeaveAction.runningList(LeaveAction.java:112)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
   at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
   at
        ………………
6 REPLIES 6

kafeitu
Champ on-the-rise
Champ on-the-rise
in module activiti-spring, I modify class CustomTaskAssignmentTest method testSetAssigneeThroughSpringService:

@Deployment
  public void testSetAssigneeThroughSpringService() {
    runtimeService.startProcessInstanceByKey("assigneeThroughSpringService", CollectionUtil.singletonMap("emp", "fozzie"));
    Task singleResult = taskService.createTaskQuery().taskAssignee("Kermit The Frog").singleResult();
    TaskEntity te = (TaskEntity)singleResult;
    System.out.println(te.getIdentityLinks());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("Kermit The Frog").count());
  }
expcetion traces:

java.lang.NullPointerException
at org.activiti.engine.impl.persistence.entity.TaskEntity.getIdentityLinks(TaskEntity.java:340)
at org.activiti.spring.test.taskassignment.CustomTaskAssignmentTest.testSetAssigneeThroughSpringService(CustomTaskAssignmentTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at org.activiti.engine.impl.test.PvmTestCase.runTest(PvmTestCase.java:75)
at junit.framework.TestCase.runBare(TestCase.java:134)
at org.activiti.engine.impl.test.AbstractActivitiTestCase.runBare(AbstractActivitiTestCase.java:89)
at org.activiti.spring.impl.test.SpringActivitiTestCase.runBare(SpringActivitiTestCase.java:51)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


kafeitu
Champ on-the-rise
Champ on-the-rise
and i try to run codes:

System.out.println(Context.getCommandContext());
result: null

who can help me ?

trademak
Star Contributor
Star Contributor
Hi,

Can you provide a unit test project, so I can reproduce the error message?

Best regards,

kafeitu
Champ on-the-rise
Champ on-the-rise
Hi,

Can you provide a unit test project, so I can reproduce the error message?

Best regards,

I used "activiti-spring-example" moudle of activiti, Test class Smiley Surprisedrg.activiti.spring.test.taskassignment.CustomTaskAssignmentTest
please override method testSetAssigneeThroughSpringService

@Deployment
public void testSetAssigneeThroughSpringService() {
  runtimeService.startProcessInstanceByKey("assigneeThroughSpringService",
    CollectionUtil.singletonMap("emp", "fozzie"));
  Task singleResult = taskService.createTaskQuery().taskAssignee("Kermit The Frog").singleResult();
  System.out.println(Context.getCommandContext());
  TaskEntity te = (TaskEntity) singleResult;
  System.out.println(te.getIdentityLinks());
  assertEquals(1, taskService.createTaskQuery().taskAssignee("Kermit The Frog").count());
}

trademak
Star Contributor
Star Contributor
I see. the task assignee is kermit, not Kermit the frog.

Best regards,

kafeitu
Champ on-the-rise
Champ on-the-rise
I see. the task assignee is kermit, not Kermit the frog.

Best regards,

You may have misunderstood what I mean.

assertEquals(1, taskService.createTaskQuery().taskAssignee("Kermit The Frog").count());
you can test the new unit test that i upgraded:

@Deployment
public void testSetAssigneeThroughSpringService() {
  runtimeService.startProcessInstanceByKey("assigneeThroughSpringService",
    CollectionUtil.singletonMap("emp", "fozzie"));
  Task singleResult = taskService.createTaskQuery().taskAssignee("Kermit The Frog").singleResult();
  TaskEntity te = (TaskEntity) singleResult;
  assertNotNull(te);
  assertNotNull(Context.getCommandContext());
  System.out.println(te.getIdentityLinks());
  assertEquals(1, taskService.createTaskQuery().taskAssignee("Kermit The Frog").count());
}
A failure to execute when assertNotNull(Context.getCommandContext());