docs: public static Map<ScopeImpl, PvmExecutionImpl> createActivityExecutionMapping(List<PvmExecutionImpl> scopeExecutions, List<ScopeImpl> scopes) {
      PvmExecutionImpl deepestExecution = scopeExecutions.get(0);
      if (isLegacyAsyncAtMultiInstance(deepestExecution)) {
        // in case the deepest execution is in fact async at multi-instance, the multi instance body is part
        // of the list of scopes, however it is not instantiated yet or has already ended. Thus it must be removed.
        scopes.remove(0);
      }
  
      // The trees are out of sync.
      // We are missing executions:
      int numOfMissingExecutions = scopes.size() - scopeExecutions.size();
  
      // We need to find out which executions are missing.
      // Consider: elements which did not use to be scopes are now scopes.
      // But, this does not mean that all instances of elements which became scopes
      // are missing their executions. We could have created new instances in the
      // lower part of the tree after legacy behavior was turned off while instances of these elements
      // further up the hierarchy miss scopes. So we need to iterate from the top down and skip all scopes which
      // were not scopes before:
      Collections.reverse(scopeExecutions);
      Collections.reverse(scopes);
  
      Map<ScopeImpl, PvmExecutionImpl> mapping  = new HashMap<ScopeImpl, PvmExecutionImpl>();
      // process definition / process instance.
      mapping.put(scopes.get(0), scopeExecutions.get(0));
      // nested activities
      int executionCounter = 0;
      for(int i = 1; i < scopes.size(); i++) {
        ActivityImpl scope = (ActivityImpl) scopes.get(i);
  
        PvmExecutionImpl scopeExecutionCandidate = null;
        if (executionCounter + 1 < scopeExecutions.size()) {
          scopeExecutionCandidate = scopeExecutions.get(executionCounter + 1);
        }
  
        if(numOfMissingExecutions > 0 && wasNoScope(scope, scopeExecutionCandidate)) {
          // found a missing scope
          numOfMissingExecutions--;
        }
        else {
          executionCounter++;
        }
  
        if (executionCounter >= scopeExecutions.size()) {
          throw new ProcessEngineException("Cannot construct activity-execution mapping: there are "
              + "more scope executions missing than explained by the flow scope hierarchy.");
        }
  
        PvmExecutionImpl execution = scopeExecutions.get(executionCounter);
        mapping.put(scope, execution);
      }
  
      return mapping;
    }