Program: 29024
Project: 29024
Buggy source:
private void appendToOutputChunk(StreamEventCloner streamEventCloner,List<ComplexEventChunk<StreamEvent>> complexEventChunks,long currentTime){
  ComplexEventChunk<StreamEvent> newEventChunk=new ComplexEventChunk<StreamEvent>(true);
  ComplexEventChunk<StreamEvent> sentEventChunk=new ComplexEventChunk<StreamEvent>(true);
  if (currentEventChunk.getFirst() != null) {
    if (expiredEventChunk.getFirst() != null) {
      expiredEventChunk.reset();
      while (expiredEventChunk.hasNext()) {
        StreamEvent expiredEvent=expiredEventChunk.next();
        if (outputExpectsExpiredEvents) {
          StreamEvent toExpireEvent=streamEventCloner.copyStreamEvent(expiredEvent);
          toExpireEvent.setTimestamp(currentTime);
          newEventChunk.add(toExpireEvent);
        }
        StreamEvent toSendEvent=streamEventCloner.copyStreamEvent(expiredEvent);
        toSendEvent.setType(ComplexEvent.Type.CURRENT);
        sentEventChunk.add(toSendEvent);
      }
    }
    StreamEvent toResetEvent=streamEventCloner.copyStreamEvent(resetEvent);
    toResetEvent.setTimestamp(currentTime);
    newEventChunk.add(toResetEvent);
    newEventChunk.add(sentEventChunk.getFirst());
    if (expiredEventChunk != null) {
      currentEventChunk.reset();
      while (currentEventChunk.hasNext()) {
        StreamEvent currentEvent=currentEventChunk.next();
        StreamEvent toExpireEvent=streamEventCloner.copyStreamEvent(currentEvent);
        toExpireEvent.setType(StreamEvent.Type.EXPIRED);
        expiredEventChunk.add(toExpireEvent);
      }
    }
    newEventChunk.add(currentEventChunk.getFirst());
  }
  currentEventChunk.clear();
  if (newEventChunk.getFirst() != null) {
    complexEventChunks.add(newEventChunk);
  }
}

Fixed version (ground truth):
private void appendToOutputChunk(StreamEventCloner streamEventCloner,List<ComplexEventChunk<StreamEvent>> complexEventChunks,long currentTime,boolean preserveCurrentEvents){
  ComplexEventChunk<StreamEvent> newEventChunk=new ComplexEventChunk<StreamEvent>(true);
  ComplexEventChunk<StreamEvent> sentEventChunk=new ComplexEventChunk<StreamEvent>(true);
  if (currentEventChunk.getFirst() != null) {
    if (expiredEventChunk.getFirst() != null) {
      expiredEventChunk.reset();
      while (expiredEventChunk.hasNext()) {
        StreamEvent expiredEvent=expiredEventChunk.next();
        if (outputExpectsExpiredEvents) {
          StreamEvent toExpireEvent=streamEventCloner.copyStreamEvent(expiredEvent);
          toExpireEvent.setTimestamp(currentTime);
          newEventChunk.add(toExpireEvent);
        }
        StreamEvent toSendEvent=streamEventCloner.copyStreamEvent(expiredEvent);
        toSendEvent.setType(ComplexEvent.Type.CURRENT);
        sentEventChunk.add(toSendEvent);
      }
    }
    StreamEvent toResetEvent=streamEventCloner.copyStreamEvent(resetEvent);
    toResetEvent.setTimestamp(currentTime);
    newEventChunk.add(toResetEvent);
    newEventChunk.add(sentEventChunk.getFirst());
    if (preserveCurrentEvents || storeExpiredEvents) {
      currentEventChunk.reset();
      while (currentEventChunk.hasNext()) {
        StreamEvent currentEvent=currentEventChunk.next();
        StreamEvent toExpireEvent=streamEventCloner.copyStreamEvent(currentEvent);
        toExpireEvent.setType(StreamEvent.Type.EXPIRED);
        expiredEventChunk.add(toExpireEvent);
      }
    }
    newEventChunk.add(currentEventChunk.getFirst());
  }
  currentEventChunk.clear();
  if (newEventChunk.getFirst() != null) {
    complexEventChunks.add(newEventChunk);
  }
}