Program: 28763
Project: 28763
Buggy source:
private synchronized void clonePartition(String key){
  PartitionInstanceRuntime partitionInstance=this.partitionInstanceRuntimeMap.get(key);
  if (partitionInstance == null) {
    List<QueryRuntime> queryRuntimeList=new ArrayList<QueryRuntime>();
    List<QueryRuntime> partitionedQueryRuntimeList=new ArrayList<QueryRuntime>();
    for (    QueryRuntime queryRuntime : metaQueryRuntimeMap.values()) {
      QueryRuntime clonedQueryRuntime=queryRuntime.clone(key,localStreamJunctionMap);
      queryRuntimeList.add(clonedQueryRuntime);
      if (queryRuntime.isFromLocalStream()) {
        for (int i=0; i < clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
          String streamId=queryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver().getStreamId();
          StreamDefinition streamDefinition;
          if (streamId.startsWith("String_Node_Str")) {
            streamDefinition=(StreamDefinition)localStreamDefinitionMap.get(streamId);
          }
 else {
            streamDefinition=(StreamDefinition)streamDefinitionMap.get(streamId);
          }
          StreamJunction streamJunction=localStreamJunctionMap.get(streamId + key);
          if (streamJunction == null) {
            streamJunction=new StreamJunction(streamDefinition,siddhiAppContext.getExecutorService(),siddhiAppContext.getBufferSize(),siddhiAppContext);
            localStreamJunctionMap.put(streamId + key,streamJunction);
          }
          streamJunction.subscribe(clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver());
        }
      }
 else {
        partitionedQueryRuntimeList.add(clonedQueryRuntime);
      }
    }
    partitionInstanceRuntimeMap.putIfAbsent(key,new PartitionInstanceRuntime(key,queryRuntimeList));
    updatePartitionStreamReceivers(key,partitionedQueryRuntimeList);
  }
}

Fixed version (ground truth):
private synchronized void clonePartition(String key){
  PartitionInstanceRuntime partitionInstance=this.partitionInstanceRuntimeMap.get(key);
  if (partitionInstance == null) {
    List<QueryRuntime> queryRuntimeList=new ArrayList<QueryRuntime>();
    List<QueryRuntime> partitionedQueryRuntimeList=new ArrayList<QueryRuntime>();
    for (    QueryRuntime queryRuntime : metaQueryRuntimeMap.values()) {
      QueryRuntime clonedQueryRuntime=queryRuntime.clone(key,localStreamJunctionMap);
      queryRuntimeList.add(clonedQueryRuntime);
      QueryParserHelper.registerMemoryUsageTracking(clonedQueryRuntime.getQueryId(),queryRuntime,SiddhiConstants.METRIC_INFIX_QUERIES,siddhiAppContext,memoryUsageTracker);
      if (queryRuntime.isFromLocalStream()) {
        for (int i=0; i < clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
          String streamId=queryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver().getStreamId();
          StreamDefinition streamDefinition;
          if (streamId.startsWith("String_Node_Str")) {
            streamDefinition=(StreamDefinition)localStreamDefinitionMap.get(streamId);
          }
 else {
            streamDefinition=(StreamDefinition)streamDefinitionMap.get(streamId);
          }
          StreamJunction streamJunction=localStreamJunctionMap.get(streamId + key);
          if (streamJunction == null) {
            streamJunction=new StreamJunction(streamDefinition,siddhiAppContext.getExecutorService(),siddhiAppContext.getBufferSize(),siddhiAppContext);
            localStreamJunctionMap.put(streamId + key,streamJunction);
          }
          streamJunction.subscribe(clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver());
        }
      }
 else {
        partitionedQueryRuntimeList.add(clonedQueryRuntime);
      }
    }
    partitionInstanceRuntimeMap.putIfAbsent(key,new PartitionInstanceRuntime(key,queryRuntimeList));
    updatePartitionStreamReceivers(key,partitionedQueryRuntimeList);
  }
}