Program: 92256
Project: 92256
Buggy source:
private static List<ITimeEvent> getEventList(ResourcesEntry entry,long startTime,long endTime,long resolution,boolean includeNull,IProgressMonitor monitor){
  IStateSystemQuerier ssq=entry.getTrace().getStateSystem();
  startTime=Math.max(startTime,ssq.getStartTime());
  endTime=Math.min(endTime,ssq.getCurrentEndTime() + 1);
  if (endTime <= startTime) {
    return null;
  }
  List<ITimeEvent> eventList=null;
  int quark=entry.getQuark();
  try {
    if (entry.getType().equals(Type.CPU)) {
      int statusQuark=ssq.getQuarkRelative(quark,Attributes.STATUS);
      List<ITmfStateInterval> statusIntervals=ssq.queryHistoryRange(statusQuark,startTime,endTime - 1,resolution);
      eventList=new ArrayList<ITimeEvent>(statusIntervals.size());
      long lastEndTime=-1;
      for (      ITmfStateInterval statusInterval : statusIntervals) {
        if (monitor.isCanceled()) {
          return null;
        }
        int status=statusInterval.getStateValue().unboxInt();
        long time=statusInterval.getStartTime();
        long duration=statusInterval.getEndTime() - time + 1;
        if (!statusInterval.getStateValue().isNull()) {
          if (lastEndTime != time && lastEndTime != -1) {
            eventList.add(new TimeEvent(entry,lastEndTime,time - lastEndTime));
          }
          eventList.add(new ResourcesEvent(entry,time,duration,status));
          lastEndTime=time + duration;
        }
 else {
          if (includeNull) {
            eventList.add(new ResourcesEvent(entry,time,duration));
          }
        }
      }
    }
 else     if (entry.getType().equals(Type.IRQ)) {
      List<ITmfStateInterval> irqIntervals=ssq.queryHistoryRange(quark,startTime,endTime - 1,resolution);
      eventList=new ArrayList<ITimeEvent>(irqIntervals.size());
      long lastEndTime=-1;
      boolean lastIsNull=true;
      for (      ITmfStateInterval irqInterval : irqIntervals) {
        if (monitor.isCanceled()) {
          return null;
        }
        long time=irqInterval.getStartTime();
        long duration=irqInterval.getEndTime() - time + 1;
        if (!irqInterval.getStateValue().isNull()) {
          int cpu=irqInterval.getStateValue().unboxInt();
          eventList.add(new ResourcesEvent(entry,time,duration,cpu));
          lastIsNull=false;
        }
 else {
          if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
            eventList.add(new ResourcesEvent(entry,lastEndTime,time - lastEndTime,-1));
          }
          if (includeNull) {
            eventList.add(new ResourcesEvent(entry,time,duration));
          }
          lastIsNull=true;
        }
        lastEndTime=time + duration;
      }
    }
 else     if (entry.getType().equals(Type.SOFT_IRQ)) {
      List<ITmfStateInterval> softIrqIntervals=ssq.queryHistoryRange(quark,startTime,endTime - 1,resolution);
      eventList=new ArrayList<ITimeEvent>(softIrqIntervals.size());
      long lastEndTime=-1;
      boolean lastIsNull=true;
      for (      ITmfStateInterval softIrqInterval : softIrqIntervals) {
        if (monitor.isCanceled()) {
          return null;
        }
        long time=softIrqInterval.getStartTime();
        long duration=softIrqInterval.getEndTime() - time + 1;
        if (!softIrqInterval.getStateValue().isNull()) {
          int cpu=softIrqInterval.getStateValue().unboxInt();
          eventList.add(new ResourcesEvent(entry,time,duration,cpu));
        }
 else {
          if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
            eventList.add(new ResourcesEvent(entry,lastEndTime,time - lastEndTime,-1));
          }
          if (includeNull) {
            eventList.add(new ResourcesEvent(entry,time,duration));
          }
          lastIsNull=true;
        }
        lastEndTime=time + duration;
      }
    }
  }
 catch (  AttributeNotFoundException e) {
    e.printStackTrace();
  }
catch (  TimeRangeException e) {
    e.printStackTrace();
  }
catch (  StateValueTypeException e) {
    e.printStackTrace();
  }
  return eventList;
}

Fixed version (ground truth):
private static List<ITimeEvent> getEventList(ResourcesEntry entry,long startTime,long endTime,long resolution,boolean includeNull,IProgressMonitor monitor){
  IStateSystemQuerier ssq=entry.getTrace().getStateSystem();
  startTime=Math.max(startTime,ssq.getStartTime());
  endTime=Math.min(endTime,ssq.getCurrentEndTime() + 1);
  if (endTime <= startTime) {
    return null;
  }
  List<ITimeEvent> eventList=null;
  int quark=entry.getQuark();
  try {
    if (entry.getType().equals(Type.CPU)) {
      int statusQuark=ssq.getQuarkRelative(quark,Attributes.STATUS);
      List<ITmfStateInterval> statusIntervals=ssq.queryHistoryRange(statusQuark,startTime,endTime - 1,resolution,monitor);
      eventList=new ArrayList<ITimeEvent>(statusIntervals.size());
      long lastEndTime=-1;
      for (      ITmfStateInterval statusInterval : statusIntervals) {
        if (monitor.isCanceled()) {
          return null;
        }
        int status=statusInterval.getStateValue().unboxInt();
        long time=statusInterval.getStartTime();
        long duration=statusInterval.getEndTime() - time + 1;
        if (!statusInterval.getStateValue().isNull()) {
          if (lastEndTime != time && lastEndTime != -1) {
            eventList.add(new TimeEvent(entry,lastEndTime,time - lastEndTime));
          }
          eventList.add(new ResourcesEvent(entry,time,duration,status));
          lastEndTime=time + duration;
        }
 else {
          if (includeNull) {
            eventList.add(new ResourcesEvent(entry,time,duration));
          }
        }
      }
    }
 else     if (entry.getType().equals(Type.IRQ)) {
      List<ITmfStateInterval> irqIntervals=ssq.queryHistoryRange(quark,startTime,endTime - 1,resolution,monitor);
      eventList=new ArrayList<ITimeEvent>(irqIntervals.size());
      long lastEndTime=-1;
      boolean lastIsNull=true;
      for (      ITmfStateInterval irqInterval : irqIntervals) {
        if (monitor.isCanceled()) {
          return null;
        }
        long time=irqInterval.getStartTime();
        long duration=irqInterval.getEndTime() - time + 1;
        if (!irqInterval.getStateValue().isNull()) {
          int cpu=irqInterval.getStateValue().unboxInt();
          eventList.add(new ResourcesEvent(entry,time,duration,cpu));
          lastIsNull=false;
        }
 else {
          if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
            eventList.add(new ResourcesEvent(entry,lastEndTime,time - lastEndTime,-1));
          }
          if (includeNull) {
            eventList.add(new ResourcesEvent(entry,time,duration));
          }
          lastIsNull=true;
        }
        lastEndTime=time + duration;
      }
    }
 else     if (entry.getType().equals(Type.SOFT_IRQ)) {
      List<ITmfStateInterval> softIrqIntervals=ssq.queryHistoryRange(quark,startTime,endTime - 1,resolution,monitor);
      eventList=new ArrayList<ITimeEvent>(softIrqIntervals.size());
      long lastEndTime=-1;
      boolean lastIsNull=true;
      for (      ITmfStateInterval softIrqInterval : softIrqIntervals) {
        if (monitor.isCanceled()) {
          return null;
        }
        long time=softIrqInterval.getStartTime();
        long duration=softIrqInterval.getEndTime() - time + 1;
        if (!softIrqInterval.getStateValue().isNull()) {
          int cpu=softIrqInterval.getStateValue().unboxInt();
          eventList.add(new ResourcesEvent(entry,time,duration,cpu));
        }
 else {
          if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
            eventList.add(new ResourcesEvent(entry,lastEndTime,time - lastEndTime,-1));
          }
          if (includeNull) {
            eventList.add(new ResourcesEvent(entry,time,duration));
          }
          lastIsNull=true;
        }
        lastEndTime=time + duration;
      }
    }
  }
 catch (  AttributeNotFoundException e) {
    e.printStackTrace();
  }
catch (  TimeRangeException e) {
    e.printStackTrace();
  }
catch (  StateValueTypeException e) {
    e.printStackTrace();
  }
  return eventList;
}