Source:
<code>private static long executeSubProcess(StatefulKnowledgeSessionImpl ksession, String processId, Map<String, Object> parameters, ProcessInstance processInstance, SubProcessNodeInstance subProcessNodeInstance) { Process process = ksession.getKieBase().getProcess(processId); if (process == null) { logger.error("Could not find process {}", processId); logger.error("Aborting process"); processInstance.setState(ProcessInstance.STATE_ABORTED); <START> return -1; <END> } else { ProcessEventSupport eventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport(); eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, ksession); ProcessInstance subProcessInstance = null; if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) { List<String> businessKeys = new ArrayList<String>(); businessKeys.add(((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey()); businessKeys.add(processId); businessKeys.add(String.valueOf(System.currentTimeMillis())); CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory(); CorrelationKey subProcessCorrelationKey = correlationKeyFactory.newCorrelationKey(businessKeys); subProcessInstance = (ProcessInstance) ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, subProcessCorrelationKey, parameters); } else { subProcessInstance = (ProcessInstance) ksession.createProcessInstance(processId, parameters); } ((ProcessInstanceImpl) subProcessInstance).setMetaData("ParentProcessInstanceId", processInstance.getId()); ((ProcessInstanceImpl) subProcessInstance).setParentProcessInstanceId(processInstance.getId()); subProcessInstance = (ProcessInstance) ksession.startProcessInstance(subProcessInstance.getId()); subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstance.getId()); eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, ksession); if (subProcessInstance.getState() == ProcessInstance.STATE_COMPLETED) { subProcessNodeInstance.triggerCompleted(); } else { subProcessNodeInstance.addEventListeners(); } return subProcessInstance.getId(); } }</code><technical_language>I prefer throw exeption instead of returning -1</technical_language>

Target:
private static long executeSubProcess(StatefulKnowledgeSessionImpl ksession, String processId, Map<String, Object> parameters, ProcessInstance processInstance, SubProcessNodeInstance subProcessNodeInstance) { Process process = ksession.getKieBase().getProcess(processId); if (process == null) { logger.error("Could not find process {}", processId); throw new IllegalArgumentException("No process definition found with id: " + processId); } else { ProcessEventSupport eventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport(); eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, ksession); ProcessInstance subProcessInstance = null; if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) { List<String> businessKeys = new ArrayList<String>(); businessKeys.add(((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey()); businessKeys.add(processId); businessKeys.add(String.valueOf(System.currentTimeMillis())); CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory(); CorrelationKey subProcessCorrelationKey = correlationKeyFactory.newCorrelationKey(businessKeys); subProcessInstance = (ProcessInstance) ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, subProcessCorrelationKey, parameters); } else { subProcessInstance = (ProcessInstance) ksession.createProcessInstance(processId, parameters); } ((ProcessInstanceImpl) subProcessInstance).setMetaData("ParentProcessInstanceId", processInstance.getId()); ((ProcessInstanceImpl) subProcessInstance).setParentProcessInstanceId(processInstance.getId()); subProcessInstance = (ProcessInstance) ksession.startProcessInstance(subProcessInstance.getId()); subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstance.getId()); eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, ksession); if (subProcessInstance.getState() == ProcessInstance.STATE_COMPLETED) { subProcessNodeInstance.triggerCompleted(); } else { subProcessNodeInstance.addEventListeners(); } return subProcessInstance.getId(); } }