nus-yam/ex-repair huggingface dataset:
Program: 91883
Project: 91883
Buggy source:
private static ITmfTrace openTraceElement(final TmfTraceElement traceElement){
  final ITmfTrace trace=traceElement.instantiateTrace();
  final ITmfEvent traceEvent=traceElement.instantiateEvent();
  if ((trace == null) || (traceEvent == null)) {
    TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement,traceElement.getTypeName()),NLS.bind(Messages.TmfOpenTraceHelper_NoTraceOrExperimentType,traceElement.getTypeName()));
    if (trace != null) {
      trace.dispose();
    }
    return null;
  }
  try {
    trace.initTrace(traceElement.getResource(),traceElement.getLocation().getPath(),traceEvent.getClass(),traceElement.getElementPath());
  }
 catch (  final TmfTraceException e) {
    TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement,traceElement.getTypeName()),Messages.TmfOpenTraceHelper_InitError + ENDL + ENDL+ e);
    trace.dispose();
    return null;
  }
  return trace;
}

Fixed version (ground truth):
private static ITmfTrace openTraceElement(final TmfTraceElement traceElement){
  final ITmfTrace trace=traceElement.instantiateTrace();
  final ITmfEvent traceEvent=traceElement.instantiateEvent();
  if ((trace == null) || (traceEvent == null)) {
    TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement,traceElement.getTypeName()),Messages.TmfOpenTraceHelper_NoTraceType);
    if (trace != null) {
      trace.dispose();
    }
    return null;
  }
  try {
    trace.initTrace(traceElement.getResource(),traceElement.getLocation().getPath(),traceEvent.getClass(),traceElement.getElementPath());
  }
 catch (  final TmfTraceException e) {
    TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement,traceElement.getTypeName()),Messages.TmfOpenTraceHelper_InitError + ENDL + ENDL+ e);
    trace.dispose();
    return null;
  }
  return trace;
}
Program: 91884
Project: 91884
Buggy source:
/** 
 * Gets a callsite using the event name and instruction pointer O(log(n))
 * @param eventName the name of the event
 * @param ip the instruction pointer
 * @return the closest matching callsite, can be null
 */
public CTFCallsite getCallsite(String eventName,long ip){
  final TreeSet<CTFCallsite> candidates=fCallsitesByName.get(eventName);
  final CTFCallsite dummyCs=new CTFCallsite(null,null,ip,null,-1);
  final CTFCallsite callsite=candidates.ceiling(dummyCs);
  if (callsite == null) {
    return candidates.floor(dummyCs);
  }
  return callsite;
}

Fixed version (ground truth):
/** 
 * Gets a callsite using the event name and instruction pointer O(log(n))
 * @param eventName the name of the event
 * @param ip the instruction pointer
 * @return the closest matching callsite, can be null
 */
public CTFCallsite getCallsite(String eventName,long ip){
  final TreeSet<CTFCallsite> candidates=fCallsitesByName.get(eventName);
  if (candidates == null) {
    return null;
  }
  final CTFCallsite dummyCs=new CTFCallsite(null,null,ip,null,-1);
  final CTFCallsite callsite=candidates.ceiling(dummyCs);
  if (callsite == null) {
    return candidates.floor(dummyCs);
  }
  return callsite;
}
Program: 91886
Project: 91886
Buggy source:
/** 
 * Set the trace type of a   {@Link TraceTypeHelper}. Should only be used internally by this project.
 * @param resource the resource to set
 * @param traceType the  {@link TraceTypeHelper} to set the trace type to.
 * @return Status.OK_Status if successful, error is otherwise.
 * @throws CoreException An exception caused by accessing eclipse project items.
 */
public static IStatus setTraceType(IResource resource,TraceTypeHelper traceType) throws CoreException {
  String traceTypeId=traceType.getCanonicalName();
  resource.setPersistentProperty(TmfCommonConstants.TRACETYPE,traceTypeId);
  TmfProjectElement tmfProject=TmfProjectRegistry.getProject(resource.getProject(),true);
  if (resource.getParent().equals(tmfProject.getTracesFolder().getResource())) {
    refreshTraceElement(tmfProject.getTracesFolder().getTraces(),resource.getName());
  }
 else {
    for (    TmfExperimentElement experimentElement : tmfProject.getExperimentsFolder().getExperiments()) {
      if (resource.getParent().equals(experimentElement.getResource())) {
        refreshTraceElement(experimentElement.getTraces(),resource.getName());
        break;
      }
    }
  }
  tmfProject.refresh();
  return Status.OK_STATUS;
}

Fixed version (ground truth):
/** 
 * Set the trace type of a   {@Link TraceTypeHelper}. Should only be used internally by this project.
 * @param resource the resource to set
 * @param traceType the  {@link TraceTypeHelper} to set the trace type to.
 * @return Status.OK_Status if successful, error is otherwise.
 * @throws CoreException An exception caused by accessing eclipse project items.
 */
public static IStatus setTraceType(IResource resource,TraceTypeHelper traceType) throws CoreException {
  String traceTypeId=traceType.getCanonicalName();
  resource.setPersistentProperty(TmfCommonConstants.TRACETYPE,traceTypeId);
  TmfProjectElement tmfProject=TmfProjectRegistry.getProject(resource.getProject(),true);
  if (resource.getParent().equals(tmfProject.getTracesFolder().getResource())) {
    refreshTraceElement(tmfProject.getTracesFolder().getTraces(),resource.getName());
  }
 else   if (resource.getParent().equals(tmfProject.getExperimentsFolder().getResource())) {
    for (    TmfExperimentElement experimentElement : tmfProject.getExperimentsFolder().getExperiments()) {
      if (resource.equals(experimentElement.getResource())) {
        experimentElement.refreshTraceType();
        break;
      }
    }
  }
 else {
    for (    TmfExperimentElement experimentElement : tmfProject.getExperimentsFolder().getExperiments()) {
      if (resource.getParent().equals(experimentElement.getResource())) {
        refreshTraceElement(experimentElement.getTraces(),resource.getName());
        break;
      }
    }
  }
  tmfProject.refresh();
  return Status.OK_STATUS;
}
Program: 91887
Project: 91887
Buggy source:
/** 
 * Test the   {@link XmlUtils#getChildElements(Element)} and{@link XmlUtils#getChildElements(Element,String)} methods
 */
@Test public void testGetChildElements(){
  File testXmlFile=TmfXmlTestFiles.VALID_FILE.getFile();
  if ((testXmlFile == null) || !testXmlFile.exists()) {
    fail("String_Node_Str");
  }
  if (testXmlFile == null) {
    return;
  }
  Element analysis=XmlUtils.getElementInFile(testXmlFile.getAbsolutePath(),TmfXmlStrings.STATE_PROVIDER,ANALYSIS_ID);
  List<Element> values=XmlUtils.getChildElements(analysis,TmfXmlStrings.DEFINED_VALUE);
  assertEquals(12,values.size());
  values=XmlUtils.getChildElements(analysis,TmfXmlStrings.HEAD);
  assertEquals(1,values.size());
  Element head=values.get(0);
  values=XmlUtils.getChildElements(head);
  assertEquals(2,values.size());
}

Fixed version (ground truth):
/** 
 * Test the   {@link XmlUtils#getChildElements(Element)} and{@link XmlUtils#getChildElements(Element,String)} methods
 */
@Test public void testGetChildElements(){
  File testXmlFile=TmfXmlTestFiles.VALID_FILE.getFile();
  if ((testXmlFile == null) || !testXmlFile.exists()) {
    fail("String_Node_Str");
  }
  if (testXmlFile == null) {
    return;
  }
  Element analysis=XmlUtils.getElementInFile(testXmlFile.getAbsolutePath(),TmfXmlStrings.STATE_PROVIDER,ANALYSIS_ID);
  List<Element> values=XmlUtils.getChildElements(analysis,TmfXmlStrings.LOCATION);
  assertEquals(5,values.size());
  Element aLocation=values.get(0);
  List<Element> attributes=XmlUtils.getChildElements(aLocation,TmfXmlStrings.STATE_ATTRIBUTE);
  assertEquals(2,attributes.size());
  values=XmlUtils.getChildElements(analysis,TmfXmlStrings.HEAD);
  assertEquals(1,values.size());
  Element head=values.get(0);
  values=XmlUtils.getChildElements(head);
  assertEquals(2,values.size());
}
Program: 91888
Project: 91888
Buggy source:
/** 
 * Get the XML children element of an XML element, but only those of a certain type
 * @param parent The parent element to get the children from
 * @param elementTag The tag of the elements to return
 * @return The list of children {@link Element} of the parent
 */
public static List<Element> getChildElements(Element parent,String elementTag){
  NodeList nodes=parent.getElementsByTagName(elementTag);
  List<Element> childElements=new ArrayList<>();
  for (int i=0; i < nodes.getLength(); i++) {
    Element node=(Element)nodes.item(i);
    childElements.add(node);
  }
  return childElements;
}

Fixed version (ground truth):
/** 
 * Get the XML children element of an XML element, but only those of a certain type
 * @param parent The parent element to get the children from
 * @param elementTag The tag of the elements to return
 * @return The list of children {@link Element} of the parent
 */
public static List<Element> getChildElements(Element parent,String elementTag){
  NodeList nodes=parent.getElementsByTagName(elementTag);
  List<Element> childElements=new ArrayList<>();
  for (int i=0; i < nodes.getLength(); i++) {
    Element node=(Element)nodes.item(i);
    if (node.getParentNode().equals(parent)) {
      childElements.add(node);
    }
  }
  return childElements;
}
Program: 91889
Project: 91889
Buggy source:
@Override public void run(){
  if (entries != fTreeViewer.getInput()) {
    fTreeViewer.setInput(entries);
  }
 else {
    fTreeViewer.refresh();
  }
  for (  TreeColumn column : fTreeViewer.getTree().getColumns()) {
    column.pack();
  }
}

Fixed version (ground truth):
@Override public void run(){
  if (rootEntry != fTreeViewer.getInput()) {
    fTreeViewer.setInput(rootEntry);
  }
 else {
    fTreeViewer.refresh();
  }
  for (  TreeColumn column : fTreeViewer.getTree().getColumns()) {
    column.pack();
  }
}
Program: 91890
Project: 91890
Buggy source:
/** 
 * Get the current input displayed by the viewer
 * @return The input of the tree viewer
 */
protected Object getInput(){
  return fTreeViewer.getInput();
}

Fixed version (ground truth):
/** 
 * Get the current input displayed by the viewer
 * @return The input of the tree viewer, the root entry
 */
protected ITmfTreeViewerEntry getInput(){
  return (ITmfTreeViewerEntry)fTreeViewer.getInput();
}
Program: 91891
Project: 91891
Buggy source:
@Override public Object[] getElements(Object inputElement){
  if (inputElement != null) {
    try {
      return ((List<?>)inputElement).toArray(new ITmfTreeViewerEntry[0]);
    }
 catch (    ClassCastException e) {
    }
  }
  return new ITmfTreeViewerEntry[0];
}

Fixed version (ground truth):
@Override public Object[] getElements(Object inputElement){
  if (inputElement instanceof ITmfTreeViewerEntry) {
    return ((ITmfTreeViewerEntry)inputElement).getChildren().toArray(new ITmfTreeViewerEntry[0]);
  }
  return new ITmfTreeViewerEntry[0];
}
Program: 91892
Project: 91892
Buggy source:
/** 
 * Requests an update of the viewer's content in a given time range or selection time range. An extra parameter defines whether these times correspond to the selection or the visible range, as the viewer may update differently in those cases.
 * @param start The start time of the requested content
 * @param end The end time of the requested content
 * @param isSelection <code>true</code> if this time range is for a selection, <code>false</code> for the visible time range
 */
protected void updateContent(final long start,final long end,final boolean isSelection){
  Thread thread=new Thread(){
    @Override public void run(){
      final List<ITmfTreeViewerEntry> entries=updateElements(start,end,isSelection);
      if (entries != null) {
        Display.getDefault().asyncExec(new Runnable(){
          @Override public void run(){
            if (entries != fTreeViewer.getInput()) {
              fTreeViewer.setInput(entries);
            }
 else {
              fTreeViewer.refresh();
            }
            for (            TreeColumn column : fTreeViewer.getTree().getColumns()) {
              column.pack();
            }
          }
        }
);
      }
    }
  }
;
  thread.start();
}

Fixed version (ground truth):
/** 
 * Requests an update of the viewer's content in a given time range or selection time range. An extra parameter defines whether these times correspond to the selection or the visible range, as the viewer may update differently in those cases.
 * @param start The start time of the requested content
 * @param end The end time of the requested content
 * @param isSelection <code>true</code> if this time range is for a selection, <code>false</code> for the visible time range
 */
protected void updateContent(final long start,final long end,final boolean isSelection){
  Thread thread=new Thread(){
    @Override public void run(){
      final ITmfTreeViewerEntry rootEntry=updateElements(start,end,isSelection);
      if (rootEntry != null) {
        Display.getDefault().asyncExec(new Runnable(){
          @Override public void run(){
            if (rootEntry != fTreeViewer.getInput()) {
              fTreeViewer.setInput(rootEntry);
            }
 else {
              fTreeViewer.refresh();
            }
            for (            TreeColumn column : fTreeViewer.getTree().getColumns()) {
              column.pack();
            }
          }
        }
);
      }
    }
  }
;
  thread.start();
}
Program: 91893
Project: 91893
Buggy source:
/** 
 * Update the entries to the given start/end time. An extra parameter defines whether these times correspond to the selection or the visible range, as the viewer may update differently in those cases. If no update is necessary, the method should return <code>null</code>. To empty the tree, an empty list should be returned. This method is not called in the UI thread when using the default viewer content update. Resource-intensive calculations here should not block the UI.
 * @param start The start time of the requested content
 * @param end The end time of the requested content
 * @param isSelection <code>true</code> if this time range is for a selection, <code>false</code> for the visible time range
 * @return The list of entries to display or <code>null</code> if no updatenecessary
 */
protected abstract List<ITmfTreeViewerEntry> updateElements(long start,long end,boolean isSelection);

Fixed version (ground truth):
/** 
 * Update the entries to the given start/end time. An extra parameter defines whether these times correspond to the selection or the visible range, as the viewer may update differently in those cases. This methods returns a root node that is not meant to be visible. The children of this 'fake' root node are the first level of entries that will appear in the tree. If no update is necessary, the method should return <code>null</code>. To empty the tree, a root node containing an empty list of children should be returned. This method is not called in the UI thread when using the default viewer content update. Resource-intensive calculations here should not block the UI.
 * @param start The start time of the requested content
 * @param end The end time of the requested content
 * @param isSelection <code>true</code> if this time range is for a selection, <code>false</code> for the visible time range
 * @return The root entry of the list of entries to display or<code>null</code> if no update necessary
 */
protected abstract ITmfTreeViewerEntry updateElements(long start,long end,boolean isSelection);
Program: 91894
Project: 91894
Buggy source:
/** 
 * Returns the child elements of this entry.
 * @return an array of child elements
 */
List<? extends ITmfTreeViewerEntry> getChildren();

Fixed version (ground truth):
/** 
 * Returns the child elements of this entry.
 * @return an array of child elements
 */
@NonNull List<? extends ITmfTreeViewerEntry> getChildren();
Program: 91895
Project: 91895
Buggy source:
private List<ITmfTreeViewerEntry> updateEntriesList(List<ITmfTreeViewerEntry> entries,long timestamp){
  for (  final ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
    if (trace == null) {
      continue;
    }
    ITmfTreeViewerEntry traceEntry=null;
    for (    ITmfTreeViewerEntry entry : entries) {
      if (entry.getName().equals(trace.getName())) {
        traceEntry=entry;
      }
    }
    if (traceEntry == null) {
      traceEntry=buildEntriesForTrace(trace,timestamp,entries);
    }
    Iterable<ITmfAnalysisModuleWithStateSystems> modules=trace.getAnalysisModulesOfClass(ITmfAnalysisModuleWithStateSystems.class);
    for (    ITmfAnalysisModuleWithStateSystems module : modules) {
      module.schedule();
      for (      ITmfStateSystem ss : module.getStateSystems()) {
        if (ss == null) {
          continue;
        }
        ITmfTreeViewerEntry ssEntry=null;
        for (        ITmfTreeViewerEntry entry : traceEntry.getChildren()) {
          if (entry.getName().equals(ss.getSSID())) {
            ssEntry=entry;
          }
        }
        if (ssEntry == null) {
          buildEntriesForStateSystem(ss,timestamp,(TmfTreeViewerEntry)traceEntry);
        }
 else         if (ssEntry.hasChildren()) {
          updateEntriesForStateSystem(ss,timestamp,(TmfTreeViewerEntry)ssEntry);
        }
 else {
          fillEntriesForStateSystem(ss,timestamp,(TmfTreeViewerEntry)ssEntry);
        }
      }
    }
  }
  return entries;
}

Fixed version (ground truth):
private void updateEntriesList(List<ITmfTreeViewerEntry> entries,long timestamp){
  for (  final ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
    if (trace == null) {
      continue;
    }
    ITmfTreeViewerEntry traceEntry=null;
    for (    ITmfTreeViewerEntry entry : entries) {
      if (entry.getName().equals(trace.getName())) {
        traceEntry=entry;
      }
    }
    if (traceEntry == null) {
      traceEntry=buildEntriesForTrace(trace,timestamp,entries);
    }
    Iterable<ITmfAnalysisModuleWithStateSystems> modules=trace.getAnalysisModulesOfClass(ITmfAnalysisModuleWithStateSystems.class);
    for (    ITmfAnalysisModuleWithStateSystems module : modules) {
      module.schedule();
      for (      ITmfStateSystem ss : module.getStateSystems()) {
        if (ss == null) {
          continue;
        }
        ITmfTreeViewerEntry ssEntry=null;
        for (        ITmfTreeViewerEntry entry : traceEntry.getChildren()) {
          if (entry.getName().equals(ss.getSSID())) {
            ssEntry=entry;
          }
        }
        if (ssEntry == null) {
          buildEntriesForStateSystem(ss,timestamp,(TmfTreeViewerEntry)traceEntry);
        }
 else         if (ssEntry.hasChildren()) {
          updateEntriesForStateSystem(ss,timestamp,(TmfTreeViewerEntry)ssEntry);
        }
 else {
          fillEntriesForStateSystem(ss,timestamp,(TmfTreeViewerEntry)ssEntry);
        }
      }
    }
  }
}
Program: 91896
Project: 91896
Buggy source:
@Override protected List<ITmfTreeViewerEntry> updateElements(long start,long end,boolean selection){
  if (getTrace() == null) {
    return null;
  }
  List<ITmfTreeViewerEntry> entries=(List<ITmfTreeViewerEntry>)getInput();
  if ((!selection) && (entries != null)) {
    return null;
  }
  if (entries == null || fFilterStatus) {
    entries=buildEntriesList(start);
  }
 else {
    entries=updateEntriesList(entries,start);
  }
  return entries;
}

Fixed version (ground truth):
@Override protected ITmfTreeViewerEntry updateElements(long start,long end,boolean selection){
  if (getTrace() == null) {
    return null;
  }
  ITmfTreeViewerEntry root=getInput();
  if ((!selection) && (root != null)) {
    return null;
  }
  if (root == null || fFilterStatus) {
    root=buildEntries(start);
  }
 else   if (root instanceof TmfTreeViewerEntry) {
    updateEntriesList(((TmfTreeViewerEntry)root).getChildren(),start);
  }
  return root;
}
Program: 91897
Project: 91897
Buggy source:
/** 
 * Run the Long getLocation() method test.
 */
@Test public void testGetLocation(){
  CtfLocationInfo location=fixture.getLocationInfo();
  Long result=location.getTimestamp();
  assertNotNull(result);
  assertEquals("String_Node_Str",result.toString());
  assertEquals((byte)1,result.byteValue());
  assertEquals((short)1,result.shortValue());
  assertEquals(1,result.intValue());
  assertEquals(1L,result.longValue());
  assertEquals(1.0f,result.floatValue(),1.0f);
  assertEquals(1.0,result.doubleValue(),1.0);
}

Fixed version (ground truth):
/** 
 * Run the Long getLocation() method test.
 */
@Test public void testGetLocation(){
  CtfLocationInfo location=fixture.getLocationInfo();
  long result=location.getTimestamp();
  assertEquals(1L,result);
}
Program: 91898
Project: 91898
Buggy source:
/** 
 * Run the CtfLocation(ITmfTimestamp) constructor test.
 */
@Test public void testCtfLocation_timestamp(){
  ITmfTimestamp timestamp=new TmfTimestamp();
  CtfLocation result=new CtfLocation(timestamp);
  assertNotNull(result);
  assertEquals(new Long(0L),(Long)result.getLocationInfo().getTimestamp());
}

Fixed version (ground truth):
/** 
 * Run the CtfLocation(ITmfTimestamp) constructor test.
 */
@Test public void testCtfLocation_timestamp(){
  ITmfTimestamp timestamp=new TmfTimestamp();
  CtfLocation result=new CtfLocation(timestamp);
  assertNotNull(result);
  assertEquals(0L,result.getLocationInfo().getTimestamp());
}
Program: 91899
Project: 91899
Buggy source:
/** 
 * Run the CtfLocation(Long) constructor test.
 */
@Test public void testCtfLocation_long(){
  CtfLocationInfo location=new CtfLocationInfo(1,0);
  CtfLocation result=new CtfLocation(location);
  assertNotNull(result);
  assertEquals(Long.valueOf(1),(Long)result.getLocationInfo().getTimestamp());
}

Fixed version (ground truth):
/** 
 * Run the CtfLocation(Long) constructor test.
 */
@Test public void testCtfLocation_long(){
  CtfLocationInfo location=new CtfLocationInfo(1,0);
  CtfLocation result=new CtfLocation(location);
  assertNotNull(result);
  assertEquals(1L,result.getLocationInfo().getTimestamp());
}
Program: 91900
Project: 91900
Buggy source:
/** 
 * Context fuzzer. Use an amount of contexts greater than the size of the iterator cache and have them access the trace in parallel.
 * @throws InterruptedException Would fail the test
 */
@Test public void testTooManyContexts() throws InterruptedException {
  final int lwcCount=101;
  double increment=(end - begin) / lwcCount;
  final ArrayList<Long> vals=new ArrayList<>();
  final ArrayList<Thread> threads=new ArrayList<>();
  final ArrayList<CtfTmfContext> tooManyContexts=new ArrayList<>();
  for (double i=begin; i < end; i+=increment) {
    SeekerThread thread=new SeekerThread(){
      @Override public void run(){
        CtfTmfContext lwc=new CtfTmfContext(trace);
        lwc.seek(val);
        trace.getNext(lwc);
synchronized (trace) {
          if (lwc.getCurrentEvent() != null) {
            vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
          }
          tooManyContexts.add(lwc);
        }
      }
    }
;
    thread.setVal((long)i);
    threads.add(thread);
    thread.start();
  }
  for (  Thread t : threads) {
    t.join();
  }
  for (  Long val : vals) {
    assertTrue(val >= begin);
    assertTrue(val <= end);
  }
}

Fixed version (ground truth):
/** 
 * Context fuzzer. Use an amount of contexts greater than the size of the iterator cache and have them access the trace in parallel.
 * @throws InterruptedException Would fail the test
 */
@Test public void testTooManyContexts() throws InterruptedException {
  final int lwcCount=101;
  double increment=(end - begin) / lwcCount;
  final ArrayList<Long> vals=new ArrayList<>();
  final ArrayList<Thread> threads=new ArrayList<>();
  final ArrayList<CtfTmfContext> tooManyContexts=new ArrayList<>();
  for (double i=begin; i < end; i+=increment) {
    SeekerThread thread=new SeekerThread(){
      @Override public void run(){
        CtfTmfContext lwc=new CtfTmfContext(trace);
        lwc.seek(val);
        trace.getNext(lwc);
synchronized (trace) {
          if (lwc.getCurrentEvent() != null) {
            vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
          }
          tooManyContexts.add(lwc);
        }
      }
    }
;
    thread.setVal((long)i);
    threads.add(thread);
    thread.start();
  }
  for (  Thread t : threads) {
    t.join();
  }
  for (  long val : vals) {
    assertTrue(val >= begin);
    assertTrue(val <= end);
  }
}
Program: 91902
Project: 91902
Buggy source:
/** 
 * Test the   {@link ITmfStatistics#histogramQuery} method over the wholetrace.
 */
@Test public void testHistogramQueryFull(){
  final int NB_REQ=10;
  List<Long> results=backend.histogramQuery(tStart,tEnd,NB_REQ);
  assertEquals(NB_REQ,results.size());
  long count=0;
  for (  Long val : results) {
    count+=val;
  }
  assertEquals(totalNbEvents,count);
  assertEquals(94161,results.get(0).longValue());
  assertEquals(87348,results.get(1).longValue());
  assertEquals(58941,results.get(2).longValue());
  assertEquals(59879,results.get(3).longValue());
  assertEquals(66941,results.get(4).longValue());
  assertEquals(68939,results.get(5).longValue());
  assertEquals(72746,results.get(6).longValue());
  assertEquals(60749,results.get(7).longValue());
  assertEquals(61208,results.get(8).longValue());
  assertEquals(64407,results.get(9).longValue());
}

Fixed version (ground truth):
/** 
 * Test the   {@link ITmfStatistics#histogramQuery} method over the wholetrace.
 */
@Test public void testHistogramQueryFull(){
  final int NB_REQ=10;
  List<Long> results=backend.histogramQuery(tStart,tEnd,NB_REQ);
  assertEquals(NB_REQ,results.size());
  long count=0;
  for (  long val : results) {
    count+=val;
  }
  assertEquals(totalNbEvents,count);
  assertEquals(94161,results.get(0).longValue());
  assertEquals(87348,results.get(1).longValue());
  assertEquals(58941,results.get(2).longValue());
  assertEquals(59879,results.get(3).longValue());
  assertEquals(66941,results.get(4).longValue());
  assertEquals(68939,results.get(5).longValue());
  assertEquals(72746,results.get(6).longValue());
  assertEquals(60749,results.get(7).longValue());
  assertEquals(61208,results.get(8).longValue());
  assertEquals(64407,results.get(9).longValue());
}
Program: 91903
Project: 91903
Buggy source:
private static long sumOfEvents(Map<String,Long> map){
  long count=0;
  for (  Long val : map.values()) {
    count+=val;
  }
  return count;
}

Fixed version (ground truth):
private static long sumOfEvents(Map<String,Long> map){
  long count=0;
  for (  long val : map.values()) {
    count+=val;
  }
  return count;
}
Program: 91904
Project: 91904
Buggy source:
/** 
 * Tests that binarySearch finds the correct checkpoint when searching for a checkpoint with a null location. It should return the previous checkpoint from the first checkpoint that matches the timestamp.
 */
@Test public void testBinarySearchInBetweenSameTimestamp(){
  int checkpointNum=0;
  for (; checkpointNum < 100; checkpointNum++) {
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(0),new TmfLongLocation((long)checkpointNum),checkpointNum);
    fCheckpointCollection.insert(checkpoint);
  }
  for (; checkpointNum < 200; checkpointNum++) {
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(1),new TmfLongLocation((long)checkpointNum),checkpointNum);
    fCheckpointCollection.insert(checkpoint);
  }
  final TmfCheckpoint searchedCheckpoint=new TmfCheckpoint(new TmfTimestamp(1),null,0);
  long found=fCheckpointCollection.binarySearch(searchedCheckpoint);
  int expectedInsertionPoint=99;
  int expectedRank=-(expectedInsertionPoint + 2);
  assertEquals(expectedRank,found);
}

Fixed version (ground truth):
/** 
 * Tests that binarySearch finds the correct checkpoint when searching for a checkpoint with a null location. It should return the previous checkpoint from the first checkpoint that matches the timestamp.
 */
@Test public void testBinarySearchInBetweenSameTimestamp(){
  int checkpointNum=0;
  for (; checkpointNum < 100; checkpointNum++) {
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(0),new TmfLongLocation(checkpointNum),checkpointNum);
    fCheckpointCollection.insert(checkpoint);
  }
  for (; checkpointNum < 200; checkpointNum++) {
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(1),new TmfLongLocation(checkpointNum),checkpointNum);
    fCheckpointCollection.insert(checkpoint);
  }
  final TmfCheckpoint searchedCheckpoint=new TmfCheckpoint(new TmfTimestamp(1),null,0);
  long found=fCheckpointCollection.binarySearch(searchedCheckpoint);
  int expectedInsertionPoint=99;
  int expectedRank=-(expectedInsertionPoint + 2);
  assertEquals(expectedRank,found);
}
Program: 91905
Project: 91905
Buggy source:
/** 
 * Tests that accepts find the correct checkpoint and ends with a perfect match
 */
@Test public void testAccept(){
  for (int i=0; i < CHECKPOINTS_INSERT_NUM; i++) {
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(i),new TmfLongLocation((long)i),0);
    fBTree.insert(checkpoint);
  }
  final TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(123),new TmfLongLocation(123L),0);
class TestVisitor implements IBTreeVisitor {
    public int fLastCompare=0;
    ITmfCheckpoint fFoundCheckpoint;
    @Override public int compare(    ITmfCheckpoint checkRec){
      fLastCompare=checkRec.compareTo(checkpoint);
      if (fLastCompare == 0) {
        fFoundCheckpoint=checkRec;
      }
      return fLastCompare;
    }
  }
  final TestVisitor t=new TestVisitor();
  fBTree.accept(t);
  assertEquals(checkpoint,t.fFoundCheckpoint);
  assertEquals(0,t.fLastCompare);
}

Fixed version (ground truth):
/** 
 * Tests that accepts find the correct checkpoint and ends with a perfect match
 */
@Test public void testAccept(){
  for (int i=0; i < CHECKPOINTS_INSERT_NUM; i++) {
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(i),new TmfLongLocation(i),0);
    fBTree.insert(checkpoint);
  }
  final TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(123),new TmfLongLocation(123L),0);
class TestVisitor implements IBTreeVisitor {
    public int fLastCompare=0;
    ITmfCheckpoint fFoundCheckpoint;
    @Override public int compare(    ITmfCheckpoint checkRec){
      fLastCompare=checkRec.compareTo(checkpoint);
      if (fLastCompare == 0) {
        fFoundCheckpoint=checkRec;
      }
      return fLastCompare;
    }
  }
  final TestVisitor t=new TestVisitor();
  fBTree.accept(t);
  assertEquals(checkpoint,t.fFoundCheckpoint);
  assertEquals(0,t.fLastCompare);
}
Program: 91906
Project: 91906
Buggy source:
/** 
 * Test many checkpoint insertions. Make sure they can be found after re-opening the file
 */
@Test public void testInsertAlotCheckEquals(){
  ArrayList<Integer> list=insertAlot();
  fFlatArray=createCollection();
  for (int i=0; i < CHECKPOINTS_INSERT_NUM; i++) {
    Integer checkpointIndex=list.get(i);
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(12345 + checkpointIndex),new TmfLongLocation(123456L + checkpointIndex),checkpointIndex);
    ITmfCheckpoint found=fFlatArray.get(checkpointIndex);
    assertEquals(checkpoint,found);
  }
}

Fixed version (ground truth):
/** 
 * Test many checkpoint insertions. Make sure they can be found after re-opening the file
 */
@Test public void testInsertAlotCheckEquals(){
  ArrayList<Integer> list=insertAlot();
  fFlatArray=createCollection();
  for (int i=0; i < CHECKPOINTS_INSERT_NUM; i++) {
    int checkpointIndex=list.get(i);
    TmfCheckpoint checkpoint=new TmfCheckpoint(new TmfTimestamp(12345 + checkpointIndex),new TmfLongLocation(123456L + checkpointIndex),checkpointIndex);
    ITmfCheckpoint found=fFlatArray.get(checkpointIndex);
    assertEquals(checkpoint,found);
  }
}
Program: 91907
Project: 91907
Buggy source:
@Override public Object getParameter(String name){
  Object value=super.getParameter(name);
  if ((value != null) && name.equals(PARAM_TEST) && (value instanceof String)) {
    return Integer.parseInt((String)value);
  }
  return value;
}

Fixed version (ground truth):
@Override public Object getParameter(String name){
  Object value=super.getParameter(name);
  if ((value != null) && name.equals(PARAM_TEST) && (value instanceof String)) {
    return Integer.decode((String)value);
  }
  return value;
}
Program: 91908
Project: 91908
Buggy source:
@Override public ITmfEvent parseEvent(final ITmfContext context){
  if (!(fEventStream instanceof TmfTraceStub)) {
    return null;
  }
  final RandomAccessFile stream=((TmfTraceStub)fEventStream).getStream();
  if (stream == null) {
    return null;
  }
  long location=0;
  if (context != null && context.getLocation() != null) {
    location=(Long)context.getLocation().getLocationInfo();
    try {
      stream.seek(location);
      final long ts=stream.readLong();
      final String source=stream.readUTF();
      final String type=stream.readUTF();
      final Integer reference=stream.readInt();
      final int typeIndex=Integer.parseInt(type.substring(typePrefix.length()));
      final String[] fields=new String[typeIndex];
      for (int i=0; i < typeIndex; i++) {
        fields[i]=stream.readUTF();
      }
      final StringBuffer content=new StringBuffer("String_Node_Str");
      if (typeIndex > 0) {
        content.append(fields[0]);
      }
      for (int i=1; i < typeIndex; i++) {
        content.append("String_Node_Str").append(fields[i]);
      }
      content.append("String_Node_Str");
      final TmfEventField root=new TmfEventField(ITmfEventField.ROOT_FIELD_ID,content.toString(),null);
      final ITmfEvent event=new TmfEvent(fEventStream,new TmfTimestamp(ts,-3,0),source,fTypes[typeIndex],root,reference.toString());
      return event;
    }
 catch (    final EOFException e) {
    }
catch (    final IOException e) {
    }
  }
  return null;
}

Fixed version (ground truth):
@Override public ITmfEvent parseEvent(final ITmfContext context){
  if (!(fEventStream instanceof TmfTraceStub)) {
    return null;
  }
  final RandomAccessFile stream=((TmfTraceStub)fEventStream).getStream();
  if (stream == null) {
    return null;
  }
  long location=0;
  if (context != null && context.getLocation() != null) {
    location=(Long)context.getLocation().getLocationInfo();
    try {
      stream.seek(location);
      final long ts=stream.readLong();
      final String source=stream.readUTF();
      final String type=stream.readUTF();
      final int reference=stream.readInt();
      final int typeIndex=Integer.parseInt(type.substring(typePrefix.length()));
      final String[] fields=new String[typeIndex];
      for (int i=0; i < typeIndex; i++) {
        fields[i]=stream.readUTF();
      }
      final StringBuffer content=new StringBuffer("String_Node_Str");
      if (typeIndex > 0) {
        content.append(fields[0]);
      }
      for (int i=1; i < typeIndex; i++) {
        content.append("String_Node_Str").append(fields[i]);
      }
      content.append("String_Node_Str");
      final TmfEventField root=new TmfEventField(ITmfEventField.ROOT_FIELD_ID,content.toString(),null);
      final ITmfEvent event=new TmfEvent(fEventStream,new TmfTimestamp(ts,-3,0),source,fTypes[typeIndex],root,String.valueOf(reference));
      return event;
    }
 catch (    final EOFException e) {
    }
catch (    final IOException e) {
    }
  }
  return null;
}
Program: 91909
Project: 91909
Buggy source:
@Override public double getLocationRatio(ITmfLocation location){
  fLock.lock();
  try {
    if (fTrace != null) {
      if (location.getLocationInfo() instanceof Long) {
        return (double)((Long)location.getLocationInfo()) / fTrace.length();
      }
    }
  }
 catch (  final IOException e) {
    e.printStackTrace();
  }
 finally {
    fLock.unlock();
  }
  return 0;
}

Fixed version (ground truth):
@Override public double getLocationRatio(ITmfLocation location){
  fLock.lock();
  try {
    if (fTrace != null) {
      if (location.getLocationInfo() instanceof Long) {
        return ((Long)location.getLocationInfo()).doubleValue() / fTrace.length();
      }
    }
  }
 catch (  final IOException e) {
    e.printStackTrace();
  }
 finally {
    fLock.unlock();
  }
  return 0;
}
Program: 91910
Project: 91910
Buggy source:
@Override public void removeAttribute(long t,int attributeQuark) throws TimeRangeException, AttributeNotFoundException {
  assert(attributeQuark >= 0);
  List<Integer> childAttributes;
  childAttributes=getSubAttributes(attributeQuark,false);
  for (  Integer childNodeQuark : childAttributes) {
    assert(attributeQuark != childNodeQuark);
    removeAttribute(t,childNodeQuark);
  }
  try {
    transState.processStateChange(t,TmfStateValue.nullValue(),attributeQuark);
  }
 catch (  StateValueTypeException e) {
    throw new IllegalStateException(e);
  }
}

Fixed version (ground truth):
@Override public void removeAttribute(long t,int attributeQuark) throws TimeRangeException, AttributeNotFoundException {
  assert(attributeQuark >= 0);
  List<Integer> childAttributes;
  childAttributes=getSubAttributes(attributeQuark,false);
  for (  int childNodeQuark : childAttributes) {
    assert(attributeQuark != childNodeQuark);
    removeAttribute(t,childNodeQuark);
  }
  try {
    transState.processStateChange(t,TmfStateValue.nullValue(),attributeQuark);
  }
 catch (  StateValueTypeException e) {
    throw new IllegalStateException(e);
  }
}
Program: 91911
Project: 91911
Buggy source:
@Override public void pushAttribute(long t,ITmfStateValue value,int attributeQuark) throws TimeRangeException, AttributeNotFoundException, StateValueTypeException {
  Integer stackDepth;
  int subAttributeQuark;
  ITmfStateValue previousSV=transState.getOngoingStateValue(attributeQuark);
  if (previousSV.isNull()) {
    stackDepth=0;
  }
 else   if (previousSV.getType() == Type.INTEGER) {
    stackDepth=previousSV.unboxInt();
  }
 else {
    throw new StateValueTypeException();
  }
  if (stackDepth >= 100000) {
    String message="String_Node_Str";
    throw new AttributeNotFoundException(message);
  }
  stackDepth++;
  subAttributeQuark=getQuarkRelativeAndAdd(attributeQuark,stackDepth.toString());
  modifyAttribute(t,TmfStateValue.newValueInt(stackDepth),attributeQuark);
  modifyAttribute(t,value,subAttributeQuark);
}

Fixed version (ground truth):
@Override public void pushAttribute(long t,ITmfStateValue value,int attributeQuark) throws TimeRangeException, AttributeNotFoundException, StateValueTypeException {
  int stackDepth;
  int subAttributeQuark;
  ITmfStateValue previousSV=transState.getOngoingStateValue(attributeQuark);
  if (previousSV.isNull()) {
    stackDepth=0;
  }
 else   if (previousSV.getType() == Type.INTEGER) {
    stackDepth=previousSV.unboxInt();
  }
 else {
    throw new StateValueTypeException();
  }
  if (stackDepth >= 100000) {
    String message="String_Node_Str";
    throw new AttributeNotFoundException(message);
  }
  stackDepth++;
  subAttributeQuark=getQuarkRelativeAndAdd(attributeQuark,String.valueOf(stackDepth));
  modifyAttribute(t,TmfStateValue.newValueInt(stackDepth),attributeQuark);
  modifyAttribute(t,value,subAttributeQuark);
}
Program: 91912
Project: 91912
Buggy source:
@Override public ITmfStateValue popAttribute(long t,int attributeQuark) throws AttributeNotFoundException, TimeRangeException, StateValueTypeException {
  ITmfStateValue previousSV=queryOngoingState(attributeQuark);
  if (previousSV.isNull()) {
    return null;
  }
  if (previousSV.getType() != Type.INTEGER) {
    throw new StateValueTypeException();
  }
  Integer stackDepth=previousSV.unboxInt();
  if (stackDepth <= 0) {
    String message="String_Node_Str" + "String_Node_Str";
    throw new StateValueTypeException(message);
  }
  int subAttributeQuark=getQuarkRelative(attributeQuark,stackDepth.toString());
  ITmfStateValue poppedValue=queryOngoingState(subAttributeQuark);
  ITmfStateValue nextSV;
  if (--stackDepth == 0) {
    nextSV=TmfStateValue.nullValue();
  }
 else {
    nextSV=TmfStateValue.newValueInt(stackDepth);
  }
  modifyAttribute(t,nextSV,attributeQuark);
  removeAttribute(t,subAttributeQuark);
  return poppedValue;
}

Fixed version (ground truth):
@Override public ITmfStateValue popAttribute(long t,int attributeQuark) throws AttributeNotFoundException, TimeRangeException, StateValueTypeException {
  ITmfStateValue previousSV=queryOngoingState(attributeQuark);
  if (previousSV.isNull()) {
    return null;
  }
  if (previousSV.getType() != Type.INTEGER) {
    throw new StateValueTypeException();
  }
  int stackDepth=previousSV.unboxInt();
  if (stackDepth <= 0) {
    String message="String_Node_Str" + "String_Node_Str";
    throw new StateValueTypeException(message);
  }
  int subAttributeQuark=getQuarkRelative(attributeQuark,String.valueOf(stackDepth));
  ITmfStateValue poppedValue=queryOngoingState(subAttributeQuark);
  ITmfStateValue nextSV;
  if (--stackDepth == 0) {
    nextSV=TmfStateValue.nullValue();
  }
 else {
    nextSV=TmfStateValue.newValueInt(stackDepth);
  }
  modifyAttribute(t,nextSV,attributeQuark);
  removeAttribute(t,subAttributeQuark);
  return poppedValue;
}
Program: 91913
Project: 91913
Buggy source:
@Override public ITmfStateInterval querySingleStackTop(long t,int stackAttributeQuark) throws StateValueTypeException, AttributeNotFoundException, TimeRangeException, StateSystemDisposedException {
  ITmfStateValue curStackStateValue=querySingleState(t,stackAttributeQuark).getStateValue();
  if (curStackStateValue.isNull()) {
    return null;
  }
  Integer curStackDepth=curStackStateValue.unboxInt();
  if (curStackDepth <= 0) {
    throw new StateValueTypeException();
  }
  int subAttribQuark=getQuarkRelative(stackAttributeQuark,curStackDepth.toString());
  return querySingleState(t,subAttribQuark);
}

Fixed version (ground truth):
@Override public ITmfStateInterval querySingleStackTop(long t,int stackAttributeQuark) throws StateValueTypeException, AttributeNotFoundException, TimeRangeException, StateSystemDisposedException {
  ITmfStateValue curStackStateValue=querySingleState(t,stackAttributeQuark).getStateValue();
  if (curStackStateValue.isNull()) {
    return null;
  }
  int curStackDepth=curStackStateValue.unboxInt();
  if (curStackDepth <= 0) {
    throw new StateValueTypeException();
  }
  int subAttribQuark=getQuarkRelative(stackAttributeQuark,String.valueOf(curStackDepth));
  return querySingleState(t,subAttribQuark);
}
Program: 91914
Project: 91914
Buggy source:
@Override public int compareTo(TmfLocationArray o){
  for (int i=0; i < fRanks.length; i++) {
    Long rank1=fRanks[i];
    Long rank2=o.fRanks[i];
    int result=rank1.compareTo(rank2);
    if (result != 0) {
      return result;
    }
  }
  return 0;
}

Fixed version (ground truth):
@Override public int compareTo(TmfLocationArray o){
  for (int i=0; i < fRanks.length; i++) {
    long rank1=fRanks[i];
    long rank2=o.fRanks[i];
    if (rank1 < rank2) {
      return -1;
    }
 else     if (rank1 > rank2) {
      return 1;
    }
  }
  return 0;
}
Program: 91915
Project: 91915
Buggy source:
@Override public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass){
  boolean applies=false;
  final IConfigurationElement[] tracetypeCE=fCe.getChildren(TmfAnalysisModuleSourceConfigElement.TRACETYPE_ELEM);
  for (  IConfigurationElement element : tracetypeCE) {
    Class<?> applyclass;
    try {
      applyclass=getBundle().loadClass(element.getAttribute(TmfAnalysisModuleSourceConfigElement.CLASS_ATTR));
      String classAppliesVal=element.getAttribute(TmfAnalysisModuleSourceConfigElement.APPLIES_ATTR);
      boolean classApplies=true;
      if (classAppliesVal != null) {
        classApplies=Boolean.valueOf(classAppliesVal);
      }
      if (classApplies) {
        applies=applyclass.isAssignableFrom(traceclass);
      }
 else {
        applies=!applyclass.isAssignableFrom(traceclass);
      }
    }
 catch (    ClassNotFoundException e) {
      Activator.logError("String_Node_Str",e);
    }
catch (    InvalidRegistryObjectException e) {
      Activator.logError("String_Node_Str",e);
    }
  }
  return applies;
}

Fixed version (ground truth):
@Override public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass){
  boolean applies=false;
  final IConfigurationElement[] tracetypeCE=fCe.getChildren(TmfAnalysisModuleSourceConfigElement.TRACETYPE_ELEM);
  for (  IConfigurationElement element : tracetypeCE) {
    Class<?> applyclass;
    try {
      applyclass=getBundle().loadClass(element.getAttribute(TmfAnalysisModuleSourceConfigElement.CLASS_ATTR));
      String classAppliesVal=element.getAttribute(TmfAnalysisModuleSourceConfigElement.APPLIES_ATTR);
      boolean classApplies=true;
      if (classAppliesVal != null) {
        classApplies=Boolean.parseBoolean(classAppliesVal);
      }
      if (classApplies) {
        applies=applyclass.isAssignableFrom(traceclass);
      }
 else {
        applies=!applyclass.isAssignableFrom(traceclass);
      }
    }
 catch (    ClassNotFoundException e) {
      Activator.logError("String_Node_Str",e);
    }
catch (    InvalidRegistryObjectException e) {
      Activator.logError("String_Node_Str",e);
    }
  }
  return applies;
}
Program: 91916
Project: 91916
Buggy source:
@Override public boolean isAutomatic(){
  return Boolean.valueOf(fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.AUTOMATIC_ATTR));
}

Fixed version (ground truth):
@Override public boolean isAutomatic(){
  return Boolean.parseBoolean(fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.AUTOMATIC_ATTR));
}
Program: 91917
Project: 91917
Buggy source:
/** 
 * Constructor for CTFEnumField.
 * @param enumValue The Enum value consisting of a pair of Enum value name and its long value
 * @param name The name of this field
 */
CTFEnumField(String name,CtfEnumPair enumValue){
  super(name,new CtfEnumPair(enumValue.getFirst(),enumValue.getSecond().longValue()),null);
}

Fixed version (ground truth):
/** 
 * Constructor for CTFEnumField.
 * @param enumValue The Enum value consisting of a pair of Enum value name and its long value
 * @param name The name of this field
 */
CTFEnumField(String name,CtfEnumPair enumValue){
  super(name,new CtfEnumPair(enumValue.getFirst(),enumValue.getSecond()),null);
}