Program: 28747
Project: 28747
Buggy source:
private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk){
  if (isOrderBy) {
    orderEventChunk(complexEventChunk);
  }
  complexEventChunk.reset();
  ComplexEventChunk<ComplexEvent> currentComplexEventChunk=new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
synchronized (this) {
    int limitCount=0;
    while (complexEventChunk.hasNext()) {
      ComplexEvent event=complexEventChunk.next();
switch (event.getType()) {
case CURRENT:
case EXPIRED:
        eventPopulator.populateStateEvent(event);
      String groupedByKey=groupByKeyGenerator.constructEventKey(event);
    GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupedByKey);
  for (  AttributeProcessor attributeProcessor : attributeProcessorList) {
    attributeProcessor.process(event);
  }
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
  if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
    complexEventChunk.remove();
    if (limit == SiddhiConstants.UNKNOWN_STATE) {
      currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey,event));
    }
 else {
      if (limitCount < limit) {
        currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey,event));
        limitCount++;
      }
    }
  }
}
GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
currentComplexEventChunk.reset();
if (currentComplexEventChunk.hasNext()) {
return currentComplexEventChunk;
}
return null;
}

Fixed version (ground truth):
private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk){
  complexEventChunk.reset();
  ComplexEventChunk<ComplexEvent> currentComplexEventChunk=new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
synchronized (this) {
    int limitCount=0;
    while (complexEventChunk.hasNext()) {
      ComplexEvent event=complexEventChunk.next();
switch (event.getType()) {
case CURRENT:
case EXPIRED:
        eventPopulator.populateStateEvent(event);
      String groupedByKey=groupByKeyGenerator.constructEventKey(event);
    GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupedByKey);
  for (  AttributeProcessor attributeProcessor : attributeProcessorList) {
    attributeProcessor.process(event);
  }
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
  if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
    complexEventChunk.remove();
    if (limit == SiddhiConstants.UNKNOWN_STATE) {
      currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey,event));
    }
 else {
      if (limitCount < limit) {
        currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey,event));
        limitCount++;
      }
    }
  }
}
GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (isOrderBy) {
orderEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
currentComplexEventChunk.reset();
if (currentComplexEventChunk.hasNext()) {
return currentComplexEventChunk;
}
return null;
}