Error while closing command context java.lang.NullPointerException

Hi All,

I am facing the following error while deploying a process.

Error while closing command context java.lang.NullPointerException

I have uploaded the relevant files.Please advise.

Complete Stacktrace.txt (62.3 KB)
loanApproval.bpmn (3.5 KB)

I implemented same process with some changes i.e. putting the code for querying the process definition and process instances in a separate service task and I get the following error.

Spring Bean invoked now
18-Feb-2019 06:01:33.254 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.camunda.bpm.engine.impl.interceptor.CommandContext.close Error while closing command context
org.camunda.bpm.engine.ProcessEngineException: Delegate expression {allRunningProcessInstances} did neither resolve to an implementation of interface org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior nor interface org.camunda.bpm.engine.delegate.JavaDelegate

I am uploading all the relevant files here.

applicationContext.xml (2.7 KB)
Complete stacktrace New.txt (59.2 KB)
loanApproval.bpmn (4.6 KB)
AllRunningProcessInstances.txt (1.8 KB)
CalculateInterestService.txt (1014 Bytes)
Starter.txt (1.1 KB)

Can you share the Code of your CalculateInterestService Class?

You have a nullPointer in this class apparently.

Error while closing command context
java.lang.NullPointerException
at org.camunda.bpm.getstarted.loanapproval.CalculateInterestService.execute(CalculateInterestService.java:40)

Also are you aware that you have a service task in the bpmn model that is not connected to anything?
“Get Processes and Instances”

best
Felix

I believe you are following this tutorial for this exercise.
https://docs.camunda.org/get-started/spring/service-task/

Did you follow the all the steps mentioned in the document.

Hi Felix,

Thanks for responding to my question.

PFB the code I used in the CalculateInterestService Class.Initially,the code underneath the statement “System.out.println(“Spring Bean invoked now”)” ,was part of a separate service task "Get Processes and Instances”(which i disconnected now) but it did not work so I put this code in a service task which is working but it throws NPE.

/*

  • Copyright © 2014 - 2018 camunda services GmbH and various authors (info@camunda.com)
  • Licensed under the Apache License, Version 2.0 (the “License”);
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an “AS IS” BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */
    package org.camunda.bpm.getstarted.loanapproval;

import java.util.List;

import org.camunda.bpm.BpmPlatform;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;

public class CalculateInterestService implements JavaDelegate {

public void execute(DelegateExecution delegate) throws Exception {

System.out.println("Spring Bean invoked now");

// TODO Auto-generated method stub
// get process engine and services
ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();

 // query for latest process definition with given name
 ProcessDefinition myProcessDefinition =
     repositoryService.createProcessDefinitionQuery()
         .processDefinitionName("loanApproval")
         .latestVersion()
         .singleResult();
 
 System.out.println("List of myProcessDefinition: "+ myProcessDefinition.toString());

 // list all running/unsuspended instances of the process
 List<ProcessInstance> processInstances =
     runtimeService.createProcessInstanceQuery()
         .processDefinitionId(myProcessDefinition.getId())
         .active() // we only want the unsuspended process instances
         .list();

 System.out.println("List of processInstances: "+ processInstances.toString());

}

}

Hi Techavidity,

I followed the same example but then I tried to do some experiments and included a code to query process definitions and process instances and it never worked after that.

I updated my post with the 2 different approaches I followed and both did not work.

Approach 1 : I put my code to query process definitions and process instances in a working system task but it gave me NPE.

Approach 2 : I created a separate system task having that code and it gave me the following error.

Spring Bean invoked now
18-Feb-2019 06:01:33.254 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.camunda.bpm.engine.impl.interceptor.CommandContext.close Error while closing command context
org.camunda.bpm.engine.ProcessEngineException: Delegate expression {allRunningProcessInstances} did neither resolve to an implementation of interface org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior nor interface org.camunda.bpm.engine.delegate.JavaDelegate

Please advise.

Thanks in advance.

@felix-mueller any thoughts on my issue?

HI @harish2624

one issue that you have is that your second service task “Get Processes and Instances” is missing a $ before the {allRunningProcessInstances} in the DelegateExpression in the BPMN model.

Best
Felix

1 Like

@felix-mueller Thanks a lot Felix.in fact,the missing ‘$’ was the culprit. My process is running absolutely fine now.I know,it was a rookie mistake. :slight_smile:

Very glad that you were able to solve your problem :slight_smile: :muscle: