Program: 92738
Project: 92738
Buggy source:
/** 
 * Scan the next events from all traces and return the next one in chronological order.
 * @param context
 * @return
 */
@Override public synchronized TmfEvent getNextEvent(TmfContext context){
  if (!(context instanceof TmfExperimentContext)) {
    return null;
  }
  if (!context.equals(fExperimentContext)) {
    fExperimentContext=seekLocation(context.getLocation());
  }
  TmfExperimentContext expContext=(TmfExperimentContext)context;
  int lastTrace=expContext.getLastTrace();
  if (lastTrace != TmfExperimentContext.NO_TRACE) {
    TmfContext traceContext=expContext.getContexts()[lastTrace];
    expContext.getEvents()[lastTrace]=expContext.getTraces()[lastTrace].getNextEvent(traceContext);
    expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
  }
  TmfEvent eventArray[]=expContext.getEvents();
  if (eventArray == null) {
    return null;
  }
  int trace=TmfExperimentContext.NO_TRACE;
  TmfTimestamp timestamp=TmfTimestamp.BigCrunch;
  if (eventArray.length == 1) {
    if (eventArray[0] != null) {
      timestamp=eventArray[0].getTimestamp();
      trace=0;
    }
  }
 else {
    for (int i=0; i < eventArray.length; i++) {
      TmfEvent event=eventArray[i];
      if (event != null && event.getTimestamp() != null) {
        TmfTimestamp otherTS=event.getTimestamp();
        if (otherTS.compareTo(timestamp,true) < 0) {
          trace=i;
          timestamp=otherTS;
        }
      }
    }
  }
  TmfEvent event=null;
  if (trace != TmfExperimentContext.NO_TRACE) {
    updateIndex(expContext,timestamp);
    TmfContext traceContext=expContext.getContexts()[trace];
    TmfExperimentLocation expLocation=(TmfExperimentLocation)expContext.getLocation();
    expLocation.getLocation().locations[trace]=traceContext.getLocation();
    expLocation.getRanks()[trace]=traceContext.getRank();
    expContext.setLastTrace(trace);
    expContext.updateRank(1);
    event=expContext.getEvents()[trace];
    fExperimentContext=expContext;
  }
  return event;
}

Fixed version (ground truth):
/** 
 * Scan the next events from all traces and return the next one in chronological order.
 * @param context
 * @return
 */
@Override public synchronized TmfEvent getNextEvent(TmfContext context){
  if (!(context instanceof TmfExperimentContext)) {
    return null;
  }
  if (!context.equals(fExperimentContext)) {
    fExperimentContext=seekLocation(context.getLocation());
  }
  TmfExperimentContext expContext=(TmfExperimentContext)context;
  int lastTrace=expContext.getLastTrace();
  if (lastTrace != TmfExperimentContext.NO_TRACE) {
    TmfContext traceContext=expContext.getContexts()[lastTrace];
    expContext.getEvents()[lastTrace]=expContext.getTraces()[lastTrace].getNextEvent(traceContext);
    expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
  }
  TmfEvent eventArray[]=expContext.getEvents();
  if (eventArray == null) {
    return null;
  }
  int trace=TmfExperimentContext.NO_TRACE;
  TmfTimestamp timestamp=TmfTimestamp.BigCrunch;
  if (eventArray.length == 1) {
    if (eventArray[0] != null) {
      timestamp=eventArray[0].getTimestamp();
      trace=0;
    }
  }
 else {
    for (int i=0; i < eventArray.length; i++) {
      TmfEvent event=eventArray[i];
      if (event != null && event.getTimestamp() != null) {
        TmfTimestamp otherTS=event.getTimestamp();
        if (otherTS.compareTo(timestamp,true) < 0) {
          trace=i;
          timestamp=otherTS;
        }
      }
    }
  }
  TmfEvent event=null;
  if (trace != TmfExperimentContext.NO_TRACE) {
    updateIndex(expContext,timestamp);
    TmfContext traceContext=expContext.getContexts()[trace];
    TmfExperimentLocation expLocation=(TmfExperimentLocation)expContext.getLocation();
    expLocation.getLocation().locations[trace]=traceContext.getLocation().clone();
    expLocation.getRanks()[trace]=traceContext.getRank();
    expContext.setLastTrace(trace);
    expContext.updateRank(1);
    event=expContext.getEvents()[trace];
    fExperimentContext=expContext;
  }
  return event;
}