Buggy code:
propertiesJSON . put ( key , act . getId ( ) ) ; } else if ( "timerDeclarations" . equals ( key ) ) { ArrayList < TimerDeclarationImpl > timerDeclarations = ( ( ArrayList < TimerDeclarationImpl > ) ( properties . get ( key ) ) ) ; ArrayNode timerDeclarationArray = new ObjectMapper ( ) . createArrayNode ( ) ; if ( timerDeclarations != null ) for ( TimerDeclarationImpl timerDeclaration : timerDeclarations ) { ObjectNode timerDeclarationJSON = new ObjectMapper ( ) . createObjectNode ( ) ; timerDeclarationJSON . put ( "isExclusive" , timerDeclaration . isExclusive ( ) ) ; if ( ( timerDeclaration . getRepeat ( ) ) != null ) timerDeclarationJSON . put ( "repeat" , timerDeclaration . getRepeat ( ) ) ; timerDeclarationJSON . put ( "retries" , String . valueOf ( timerDeclaration . getRetries ( ) ) ) ; timerDeclarationJSON . put ( "type" , timerDeclaration . getJobHandlerType ( ) ) ; timerDeclarationJSON . put ( "configuration" , timerDeclaration . getJobHandlerConfiguration ( ) ) ; timerDeclarationArray . add ( timerDeclarationJSON ) ; } if ( ( timerDeclarationArray . size ( ) ) > 0 ) propertiesJSON . put ( key , timerDeclarationArray ) ; } else if ( "eventDefinitions" . equals ( key ) ) { ArrayList < EventSubscriptionDeclaration > eventDefinitions = ( ( ArrayList < EventSubscriptionDeclaration > ) ( properties . get ( key ) ) ) ; ArrayNode eventDefinitionsArray = new ObjectMapper ( ) . createArrayNode ( ) ; if ( eventDefinitions != null ) { for ( EventSubscriptionDeclaration eventDefinition : eventDefinitions ) { ObjectNode eventDefinitionJSON = new ObjectMapper ( ) . createObjectNode ( ) ; if ( ( eventDefinition . getActivityId ( ) ) != null ) eventDefinitionJSON . put ( "activityId" , eventDefinition . getActivityId ( ) ) ; eventDefinitionJSON . put ( "eventName" , eventDefinition . getEventName ( ) ) ; eventDefinitionJSON . put ( "eventType" , eventDefinition . getEventType ( ) ) ; eventDefinitionJSON . put ( "isAsync" , eventDefinition . isAsync ( ) ) ; eventDefinitionJSON . put ( "isStartEvent" , eventDefinition . isStartEvent ( ) ) ; eventDefinitionsArray . add ( eventDefinitionJSON ) ; } } if ( ( eventDefinitionsArray . size ( ) ) > 0 ) propertiesJSON . put ( key , eventDefinitionsArray ) ; } else if ( "errorEventDefinitions" . equals ( key ) ) { ArrayList < ErrorEventDefinition > errorEventDefinitions = ( ( ArrayList < ErrorEventDefinition > ) ( properties . get ( key ) ) ) ; ArrayNode errorEventDefinitionsArray = new ObjectMapper ( ) . createArrayNode ( ) ; if ( errorEventDefinitions != null ) { for ( ErrorEventDefinition errorEventDefinition : errorEventDefinitions ) { ObjectNode errorEventDefinitionJSON = new ObjectMapper ( ) . createObjectNode ( ) ; if ( ( errorEventDefinition . getErrorCode ( ) ) != null ) errorEventDefinitionJSON . put ( "errorCode" , errorEventDefinition . getErrorCode ( ) ) ; else errorEventDefinitionJSON . putNull ( "errorCode" ) ; errorEventDefinitionJSON . put ( "handlerActivityId" , errorEventDefinition . getHandlerActivityId ( ) ) ; errorEventDefinitionsArray . add ( errorEventDefinitionJSON ) ; } } if ( ( errorEventDefinitionsArray . size ( ) ) > 0 ) propertiesJSON . put ( key , errorEventDefinitionsArray ) ; } } if ( "callActivity" . equals ( properties . get ( "type" ) ) ) { CallActivityBehavior callActivityBehavior = null ; if ( activityBehavior instanceof CallActivityBehavior ) { callActivityBehavior = ( ( CallActivityBehavior ) ( activityBehavior ) ) ; } if ( callActivityBehavior != null ) { propertiesJSON . put ( "processDefinitonKey" , callActivityBehavior . getProcessDefinitonKey ( ) ) ; ArrayNode processInstanceArray = new ObjectMapper ( ) . createArrayNode ( ) ; if ( processInstance != null ) { List < Execution > executionList = runtimeService . createExecutionQuery ( ) . processInstanceId ( processInstanceId ) . activityId ( activity . getId ( ) ) . list ( ) ; if ( ! ( executionList . isEmpty ( ) ) ) { for ( Execution execution : executionList ) { ObjectNode processInstanceJSON = subProcessInstanceMap . get ( execution . getId ( ) ) ; processInstanceArray . add ( processInstanceJSON ) ; } } } <START_BUG> if ( ( processInstanceArray . size ( ) ) == 0 ) { <END_BUG> ProcessDefinition lastProcessDefinition = repositoryService . createProcessDefinitionQuery ( ) . processDefinitionKey ( callActivityBehavior . getProcessDefinitonKey ( ) ) . latestVersion ( ) . singleResult ( ) ; if ( lastProcessDefinition != null ) { ObjectNode processInstanceJSON = new ObjectMapper ( ) . createObjectNode ( ) ; processInstanceJSON . put ( "processDefinitionId" , lastProcessDefinition . getId ( ) ) ; processInstanceJSON . put ( "processDefinitionKey" , lastProcessDefinition . getKey ( ) ) ; processInstanceJSON . put ( "processDefinitionName" , lastProcessDefinition . getName ( ) ) ; processInstanceArray . add ( processInstanceJSON ) ; } } if ( ( processInstanceArray . size ( ) ) > 0 ) { propertiesJSON . put ( "processDefinitons" , processInstanceArray ) ; } } } activityJSON . put ( "activityId" , activity . getId ( ) ) ; activityJSON . put ( "properties" , propertiesJSON ) ; if ( multiInstance != null ) activityJSON . put ( "multiInstance" , multiInstance ) ; if ( collapsed ) activityJSON . put ( "collapsed" , collapsed ) ; if ( ( nestedActivityArray . size ( ) ) > 0 ) activityJSON . put ( "nestedActivities" , nestedActivityArray ) ; if ( isInterrupting != null ) activityJSON . put ( "isInterrupting" , isInterrupting ) ; activityJSON . put ( "x" , activity . getX ( ) ) ; activityJSON . put ( "y" , activity . getY ( ) ) ; activityJSON . put ( "width" , activity . getWidth ( ) ) ; activityJSON . put ( "height" , activity . getHeight ( ) ) ; activityArray . add ( activityJSON ) ; for ( ActivityImpl nestedActivity : activity . getActivities ( ) ) { getActivity ( processInstanceId , nestedActivity , activityArray , sequenceFlowArray , processInstance , highLightedFlows , subProcessInstanceMap ) ; }

Fix:
if ( ( ( processInstanceArray . size ( ) ) == 0 ) && ( StringUtils . isNotEmpty ( callActivityBehavior . getProcessDefinitonKey ( ) ) ) ) {