nus-yam/ex-repair huggingface dataset:
Program: 146745
Project: 146745
Buggy source:
public void readExternal(DataInputStream in,PrototypeFactory pf) throws IOException, DeserializationException {
  id=ExtUtil.readString(in);
  title=(Text)ExtUtil.read(in,Text.class,pf);
  titleForm=ExtUtil.readString(in);
  Vector<Detail> theDetails=(Vector<Detail>)ExtUtil.read(in,new ExtWrapList(Detail.class),pf);
  details=new Detail[theDetails.size()];
  ArrayUtilities.copyIntoArray(theDetails,details);
  Vector<DetailField> theFields=(Vector<DetailField>)ExtUtil.read(in,new ExtWrapList(DetailField.class),pf);
  fields=new DetailField[theFields.size()];
  ArrayUtilities.copyIntoArray(theFields,fields);
  variables=(OrderedHashtable<String,String>)ExtUtil.read(in,new ExtWrapMap(String.class,String.class,ExtWrapMap.TYPE_SLOW_READ_ONLY));
  action=(Action)ExtUtil.read(in,new ExtWrapNullable(Action.class),pf);
}

Fixed version (ground truth):
public void readExternal(DataInputStream in,PrototypeFactory pf) throws IOException, DeserializationException {
  id=ExtUtil.readString(in);
  title=(Text)ExtUtil.read(in,Text.class,pf);
  titleForm=(String)ExtUtil.read(in,new ExtWrapNullable(String.class));
  Vector<Detail> theDetails=(Vector<Detail>)ExtUtil.read(in,new ExtWrapList(Detail.class),pf);
  details=new Detail[theDetails.size()];
  ArrayUtilities.copyIntoArray(theDetails,details);
  Vector<DetailField> theFields=(Vector<DetailField>)ExtUtil.read(in,new ExtWrapList(DetailField.class),pf);
  fields=new DetailField[theFields.size()];
  ArrayUtilities.copyIntoArray(theFields,fields);
  variables=(OrderedHashtable<String,String>)ExtUtil.read(in,new ExtWrapMap(String.class,String.class,ExtWrapMap.TYPE_SLOW_READ_ONLY));
  action=(Action)ExtUtil.read(in,new ExtWrapNullable(Action.class),pf);
}
Program: 146747
Project: 146747
Buggy source:
public TreeElement getChild(String name,int multiplicity){
  if (this.children == null) {
    return null;
  }
  if (name.equals(TreeReference.NAME_WILDCARD)) {
    if (multiplicity == TreeReference.INDEX_TEMPLATE || this.children.size() < multiplicity + 1) {
      return null;
    }
    return (TreeElement)this.children.elementAt(multiplicity);
  }
 else {
    for (int i=0; i < this.children.size(); i++) {
      TreeElement child=(TreeElement)this.children.elementAt(i);
      if ((name.hashCode() == child.getName().hashCode()) || name.equals(child.getName()) && child.getMult() == multiplicity) {
        return child;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
public TreeElement getChild(String name,int multiplicity){
  if (this.children == null) {
    return null;
  }
  if (name.equals(TreeReference.NAME_WILDCARD)) {
    if (multiplicity == TreeReference.INDEX_TEMPLATE || this.children.size() < multiplicity + 1) {
      return null;
    }
    return (TreeElement)this.children.elementAt(multiplicity);
  }
 else {
    for (int i=0; i < this.children.size(); i++) {
      TreeElement child=(TreeElement)this.children.elementAt(i);
      if (((name.hashCode() == child.getName().hashCode()) || name.equals(child.getName())) && child.getMult() == multiplicity) {
        return child;
      }
    }
  }
  return null;
}
Program: 146748
Project: 146748
Buggy source:
private void saveInstanceNode(Element instance){
  Element instanceNode=null;
  String instanceId=instance.getAttributeValue("String_Node_Str","String_Node_Str");
  for (int i=0; i < instance.getChildCount(); i++) {
    if (instance.getType(i) == Node.ELEMENT) {
      if (instanceNode != null) {
        throw new XFormParseException("String_Node_Str",instance);
      }
 else {
        instanceNode=instance.getElement(i);
      }
    }
  }
  if (instanceNode == null) {
    instanceNode=instance;
  }
  if (mainInstanceNode == null) {
    mainInstanceNode=instanceNode;
  }
  instanceNodes.addElement(instanceNode);
  instanceNodeIdStrs.addElement(instanceId);
}

Fixed version (ground truth):
private void saveInstanceNode(Element instance){
  Element instanceNode=null;
  String instanceId=instance.getAttributeValue("String_Node_Str","String_Node_Str");
  for (int i=0; i < instance.getChildCount(); i++) {
    if (instance.getType(i) == Node.ELEMENT) {
      if (instanceNode != null) {
        throw new XFormParseException("String_Node_Str",instance);
      }
 else {
        instanceNode=instance.getElement(i);
      }
    }
  }
  if (instanceNode == null) {
    instanceNode=instance;
  }
  if (mainInstanceNode == null) {
    mainInstanceNode=instanceNode;
  }
 else   if (instanceId == null) {
    throw new XFormParseException("String_Node_Str",instance);
  }
  instanceNodes.addElement(instanceNode);
  instanceNodeIdStrs.addElement(instanceId);
}
Program: 146749
Project: 146749
Buggy source:
private void parseDoc(){
  _f=new FormDef();
  initState();
  defaultNamespace=_xmldoc.getRootElement().getNamespaceUri(null);
  parseElement(_xmldoc.getRootElement(),_f,topLevelHandlers);
  collapseRepeatGroups(_f);
  if (instanceNodes.size() > 1) {
    for (int i=1; i < instanceNodes.size(); i++) {
      Element e=instanceNodes.elementAt(i);
      String srcLocation=e.getAttributeValue(null,"String_Node_Str");
      DataInstance di;
      if (e.getChildCount() == 0 && srcLocation != null) {
        di=new ExternalDataInstance(srcLocation,instanceNodeIdStrs.elementAt(i));
      }
 else {
        FormInstance fi=parseInstance(e,false);
        loadInstanceData(e,fi.getRoot(),_f);
        di=fi;
      }
      _f.addNonMainInstance(di);
    }
  }
  if (mainInstanceNode != null) {
    FormInstance fi=parseInstance(mainInstanceNode,true);
    addMainInstanceToFormDef(mainInstanceNode,fi);
    _f.setInstance(fi);
  }
}

Fixed version (ground truth):
private void parseDoc(){
  _f=new FormDef();
  initState();
  defaultNamespace=_xmldoc.getRootElement().getNamespaceUri(null);
  parseElement(_xmldoc.getRootElement(),_f,topLevelHandlers);
  collapseRepeatGroups(_f);
  if (instanceNodes.size() > 1) {
    for (int i=1; i < instanceNodes.size(); i++) {
      Element e=instanceNodes.elementAt(i);
      String srcLocation=e.getAttributeValue(null,"String_Node_Str");
      String instanceid=instanceNodeIdStrs.elementAt(i);
      DataInstance di;
      if (srcLocation != null) {
        if (e.getChildCount() > 0) {
          for (int k=0; k < e.getChildCount(); ++k) {
switch (e.getType(k)) {
case Element.TEXT:
              if ("String_Node_Str".equals(e.getText(i).trim())) {
                continue;
              }
case Element.IGNORABLE_WHITESPACE:
            continue;
case Element.ELEMENT:
          throw new XFormParseException("String_Node_Str" + instanceid + "String_Node_Str",e);
      }
    }
  }
  di=new ExternalDataInstance(srcLocation,instanceid);
}
 else {
  FormInstance fi=parseInstance(e,false);
  loadInstanceData(e,fi.getRoot(),_f);
  di=fi;
}
_f.addNonMainInstance(di);
}
}
if (mainInstanceNode != null) {
FormInstance fi=parseInstance(mainInstanceNode,true);
addMainInstanceToFormDef(mainInstanceNode,fi);
_f.setInstance(fi);
}
}
Program: 146750
Project: 146750
Buggy source:
public boolean initialize(CommCareInstance instance) throws ResourceInitializationException {
  if (cache == null) {
    Localization.registerLanguageReference(locale,localReference);
  }
 else {
    Localization.getGlobalLocalizerAdvanced().registerLocaleResource(locale,new TableLocaleSource(cache));
  }
  return true;
}

Fixed version (ground truth):
public boolean initialize(CommCareInstance instance) throws ResourceInitializationException {
  if (cache == null) {
    Localization.registerLanguageReference(locale,localReference);
  }
 else {
    Localization.getGlobalLocalizerAdvanced().addAvailableLocale(locale);
    Localization.getGlobalLocalizerAdvanced().registerLocaleResource(locale,new TableLocaleSource(cache));
  }
  return true;
}
Program: 146751
Project: 146751
Buggy source:
private static int extractNextIndex(String text,String[] args){
  int start=text.indexOf("String_Node_Str");
  int end=text.indexOf("String_Node_Str");
  if (start != -1 && end != -1) {
    String val=text.substring(start + "String_Node_Str".length(),end);
    try {
      int index=Integer.parseInt(val);
      if (index >= 0 && index < args.length) {
        return index;
      }
    }
 catch (    NumberFormatException nfe) {
      return -1;
    }
  }
  return -1;
}

Fixed version (ground truth):
private static int extractNextIndex(String text,String[] args){
  int start=text.indexOf("String_Node_Str");
  int end=text.indexOf("String_Node_Str",start);
  if (start != -1 && end != -1) {
    String val=text.substring(start + "String_Node_Str".length(),end);
    try {
      int index=Integer.parseInt(val);
      if (index >= 0 && index < args.length) {
        return index;
      }
    }
 catch (    NumberFormatException nfe) {
      return -1;
    }
  }
  return -1;
}
Program: 146752
Project: 146752
Buggy source:
private static String[] replaceFirstValue(String text,String value){
  int start=text.indexOf("String_Node_Str");
  int end=text.indexOf("String_Node_Str");
  return new String[]{text.substring(0,start) + value,text.substring(end + 1,text.length())};
}

Fixed version (ground truth):
private static String[] replaceFirstValue(String text,String value){
  int start=text.indexOf("String_Node_Str");
  int end=text.indexOf("String_Node_Str",start);
  return new String[]{text.substring(0,start) + value,text.substring(end + 1,text.length())};
}
Program: 146753
Project: 146753
Buggy source:
public static String processArguments(String text,String[] args){
  String working=text;
  int currentArg=0;
  while (working.indexOf("String_Node_Str") != -1 && args.length > currentArg) {
    int index=extractNextIndex(working,args);
    if (index == -1) {
      index=currentArg;
      currentArg++;
    }
    String value=args[index];
    working=replaceFirstValue(working,value);
  }
  return working;
}

Fixed version (ground truth):
public static String processArguments(String text,String[] args,int currentArg){
  String working=text;
  if (working.indexOf("String_Node_Str") != -1 && args.length > currentArg) {
    int index=extractNextIndex(working,args);
    if (index == -1) {
      index=currentArg;
      currentArg++;
    }
    String value=args[index];
    String[] replaced=replaceFirstValue(working,value);
    return replaced[0] + processArguments(replaced[1],args,currentArg);
  }
 else {
    return working;
  }
}
Program: 146754
Project: 146754
Buggy source:
private static String replaceFirstValue(String text,String value){
  int start=text.indexOf("String_Node_Str");
  int end=text.indexOf("String_Node_Str");
  return text.substring(0,start) + value + text.substring(end + 1,text.length());
}

Fixed version (ground truth):
private static String[] replaceFirstValue(String text,String value){
  int start=text.indexOf("String_Node_Str");
  int end=text.indexOf("String_Node_Str");
  return new String[]{text.substring(0,start) + value,text.substring(end + 1,text.length())};
}
Program: 146755
Project: 146755
Buggy source:
public Boolean parse() throws InvalidStructureException, IOException, XmlPullParserException, UnfullfilledRequirementsException {
  try {
    String rootName=parser.getName();
    if (requiredRootEnvelope != null && !requiredRootEnvelope.equals(rootName)) {
      throw new InvalidStructureException("String_Node_Str" + rootName + "String_Node_Str"+ requiredRootEnvelope+ "String_Node_Str",parser);
    }
    String itemString=parser.getAttributeValue(null,"String_Node_Str");
    int itemNumber=-1;
    if (itemString != null) {
      try {
        itemNumber=Integer.parseInt(itemString);
      }
 catch (      NumberFormatException e) {
        itemNumber=0;
      }
      rListener.setTotalForms(itemNumber);
    }
    parseBlock(rootName);
  }
  finally {
    try {
      is.close();
    }
 catch (    IOException ioe) {
    }
  }
  if (errors.size() == 0) {
    return Boolean.TRUE;
  }
 else {
    return Boolean.FALSE;
  }
}

Fixed version (ground truth):
public Boolean parse() throws InvalidStructureException, IOException, XmlPullParserException, UnfullfilledRequirementsException {
  try {
    String rootName=parser.getName();
    if (requiredRootEnvelope != null && !requiredRootEnvelope.equals(rootName)) {
      throw new InvalidStructureException("String_Node_Str" + rootName + "String_Node_Str"+ requiredRootEnvelope+ "String_Node_Str",parser);
    }
    String itemString=parser.getAttributeValue(null,"String_Node_Str");
    int itemNumber=-1;
    if (itemString != null) {
      try {
        itemNumber=Integer.parseInt(itemString);
      }
 catch (      NumberFormatException e) {
        itemNumber=0;
      }
      if (rListener != null) {
        rListener.setTotalForms(itemNumber);
      }
    }
    parseBlock(rootName);
  }
  finally {
    try {
      is.close();
    }
 catch (    IOException ioe) {
    }
  }
  if (errors.size() == 0) {
    return Boolean.TRUE;
  }
 else {
    return Boolean.FALSE;
  }
}
Program: 146758
Project: 146758
Buggy source:
protected void checkNode(String[] names) throws InvalidStructureException {
  boolean checksOut=false;
  for (  String name : names) {
    if (parser.getName().toLowerCase().equals(name)) {
      checksOut=true;
    }
  }
  if (!checksOut) {
    int eventType=-1;
    try {
      eventType=parser.getEventType();
    }
 catch (    XmlPullParserException xppe) {
    }
    String oneOf=null;
    if (names.length == 1) {
      oneOf="String_Node_Str" + names[0] + "String_Node_Str";
    }
 else {
      oneOf="String_Node_Str";
      for (      String name : names) {
        oneOf+="String_Node_Str" + name + "String_Node_Str";
      }
      oneOf+="String_Node_Str";
    }
    throw new InvalidStructureException("String_Node_Str" + oneOf + (eventType == KXmlParser.END_TAG ? "String_Node_Str" : "String_Node_Str")+ parser.getName()+ "String_Node_Str",parser);
  }
}

Fixed version (ground truth):
protected void checkNode(String[] names) throws InvalidStructureException {
  boolean checksOut=false;
  if (parser.getName() == null) {
  }
 else {
    for (    String name : names) {
      if (parser.getName().toLowerCase().equals(name)) {
        checksOut=true;
      }
    }
  }
  if (!checksOut) {
    int eventType=-1;
    try {
      eventType=parser.getEventType();
    }
 catch (    XmlPullParserException xppe) {
    }
    String oneOf=null;
    if (names.length == 1) {
      oneOf="String_Node_Str" + names[0] + "String_Node_Str";
    }
 else {
      oneOf="String_Node_Str";
      for (      String name : names) {
        oneOf+="String_Node_Str" + name + "String_Node_Str";
      }
      oneOf+="String_Node_Str";
    }
    String foundInstead="String_Node_Str";
    if (eventType == KXmlParser.END_TAG) {
      foundInstead="String_Node_Str" + parser.getName() + "String_Node_Str";
    }
 else     if (eventType == KXmlParser.START_TAG) {
      foundInstead="String_Node_Str" + parser.getName() + "String_Node_Str";
    }
 else     if (eventType == KXmlParser.TEXT) {
      foundInstead="String_Node_Str" + parser.getText() + "String_Node_Str";
    }
 else {
      foundInstead="String_Node_Str";
    }
    throw new InvalidStructureException("String_Node_Str" + oneOf + foundInstead+ "String_Node_Str",parser);
  }
}
Program: 146760
Project: 146760
Buggy source:
private TreeElement cache(){
  if (recordId == TreeReference.INDEX_TEMPLATE) {
    return empty;
  }
synchronized (parent.treeCache) {
    TreeElement element=parent.treeCache.retrieve(recordId);
    if (element != null) {
      return element;
    }
    TreeElement cacheBuilder=new TreeElement("String_Node_Str");
    Stock s=parent.storage.read(recordId);
    entityId=s.getEntiyId();
    cacheBuilder=new TreeElement("String_Node_Str");
    cacheBuilder.setMult(this.mult);
    cacheBuilder.setAttribute(null,"String_Node_Str",s.getEntiyId());
    TreeElement product;
    String[] productList=s.getProductList();
    for (int i=0; i < productList.length; ++i) {
      product=new TreeElement("String_Node_Str");
      product.setAttribute(null,"String_Node_Str",productList[i]);
      product.setValue(new IntegerData(s.getProductValue(productList[i])));
      cacheBuilder.addChild(product);
    }
    cacheBuilder.setParent(this.parent);
    parent.treeCache.register(recordId,cacheBuilder);
    return cacheBuilder;
  }
}

Fixed version (ground truth):
private TreeElement cache(){
  if (recordId == TreeReference.INDEX_TEMPLATE) {
    return empty;
  }
synchronized (parent.treeCache) {
    TreeElement element=parent.treeCache.retrieve(recordId);
    if (element != null) {
      return element;
    }
    TreeElement cacheBuilder=new TreeElement("String_Node_Str");
    Stock s=parent.storage.read(recordId);
    entityId=s.getEntiyId();
    cacheBuilder=new TreeElement("String_Node_Str");
    cacheBuilder.setMult(this.mult);
    cacheBuilder.setAttribute(null,"String_Node_Str",s.getEntiyId());
    TreeElement product;
    String[] productList=s.getProductList();
    for (int i=0; i < productList.length; ++i) {
      product=new TreeElement("String_Node_Str",i);
      product.setAttribute(null,"String_Node_Str",productList[i]);
      product.setValue(new IntegerData(s.getProductValue(productList[i])));
      cacheBuilder.addChild(product);
    }
    cacheBuilder.setParent(this.parent);
    parent.treeCache.register(recordId,cacheBuilder);
    return cacheBuilder;
  }
}
Program: 146761
Project: 146761
Buggy source:
public CommCareConfigEngine(OutputStream output){
  this.output=output;
  this.print=new PrintStream(output);
  suites=new Vector<Suite>();
  this.instance=new CommCareInstance(){
    public void registerSuite(    Suite s){
      CommCareConfigEngine.this.suites.add(s);
    }
    public void setProfile(    Profile p){
      CommCareConfigEngine.this.profile=p;
    }
    public int getMajorVersion(){
      return 2;
    }
    public int getMinorVersion(){
      return 9;
    }
  }
;
  setRoots();
  table=ResourceTable.RetrieveTable(new DummyIndexedStorageUtility());
  StorageManager.setStorageFactory(new IStorageFactory(){
    public IStorageUtility newStorage(    String name,    Class type){
      return new DummyIndexedStorageUtility();
    }
  }
);
  StorageManager.registerStorage(Profile.STORAGE_KEY,Profile.class);
  StorageManager.registerStorage(Suite.STORAGE_KEY,Suite.class);
  StorageManager.registerStorage(FormDef.STORAGE_KEY,Suite.class);
  StorageManager.registerStorage("String_Node_Str",FormInstance.class);
}

Fixed version (ground truth):
public CommCareConfigEngine(OutputStream output){
  this.output=output;
  this.print=new PrintStream(output);
  suites=new Vector<Suite>();
  this.instance=new CommCareInstance(){
    public void registerSuite(    Suite s){
      CommCareConfigEngine.this.suites.add(s);
    }
    public void setProfile(    Profile p){
      CommCareConfigEngine.this.profile=p;
    }
    public int getMajorVersion(){
      return 2;
    }
    public int getMinorVersion(){
      return 10;
    }
  }
;
  setRoots();
  table=ResourceTable.RetrieveTable(new DummyIndexedStorageUtility());
  StorageManager.setStorageFactory(new IStorageFactory(){
    public IStorageUtility newStorage(    String name,    Class type){
      return new DummyIndexedStorageUtility();
    }
  }
);
  StorageManager.registerStorage(Profile.STORAGE_KEY,Profile.class);
  StorageManager.registerStorage(Suite.STORAGE_KEY,Suite.class);
  StorageManager.registerStorage(FormDef.STORAGE_KEY,Suite.class);
  StorageManager.registerStorage("String_Node_Str",FormInstance.class);
}
Program: 146762
Project: 146762
Buggy source:
public int getMinorVersion(){
  return 9;
}

Fixed version (ground truth):
public int getMinorVersion(){
  return 10;
}
Program: 146763
Project: 146763
Buggy source:
public String entityType(){
  return shortDetail.getTitle().evaluate(context);
}

Fixed version (ground truth):
public String entityType(){
  return Localizer.clearArguments(shortDetail.getTitle().evaluate(context));
}
Program: 146764
Project: 146764
Buggy source:
protected void checkNode(String[] names) throws InvalidStructureException {
  boolean checksOut=false;
  if (parser.getName() == null) {
  }
 else {
    for (    String name : names) {
      if (parser.getName().toLowerCase().equals(name)) {
        checksOut=true;
      }
    }
  }
  if (!checksOut) {
    int eventType=-1;
    try {
      eventType=parser.getEventType();
    }
 catch (    XmlPullParserException xppe) {
    }
    String oneOf=null;
    if (names.length == 1) {
      oneOf="String_Node_Str" + names[0] + "String_Node_Str";
    }
 else {
      oneOf="String_Node_Str";
      for (      String name : names) {
        oneOf+="String_Node_Str" + name + "String_Node_Str";
      }
      oneOf+="String_Node_Str";
    }
    String foundInstead="String_Node_Str";
    if (eventType == KXmlParser.END_TAG) {
      foundInstead="String_Node_Str" + parser.getName() + "String_Node_Str";
    }
 else     if (eventType == KXmlParser.START_TAG) {
      foundInstead="String_Node_Str" + parser.getName() + "String_Node_Str";
    }
 else     if (eventType == KXmlParser.TEXT) {
      foundInstead="String_Node_Str" + parser.getText() + "String_Node_Str";
    }
 else {
      foundInstead="String_Node_Str";
    }
    throw new InvalidStructureException("String_Node_Str" + oneOf + foundInstead+ "String_Node_Str",parser);
  }
}

Fixed version (ground truth):
/** 
 * Evaluates whether the current node is of an appropriate name and throws the proper exception if not.
 * @param name A list of names which are valid during this stepof parsing
 * @throws InvalidStructureException If the node at the currentposition is not the one expected.
 */
protected void checkNode(String[] names) throws InvalidStructureException {
  boolean checksOut=false;
  if (parser.getName() == null) {
  }
 else {
    for (    String name : names) {
      if (parser.getName().toLowerCase().equals(name)) {
        checksOut=true;
      }
    }
  }
  if (!checksOut) {
    int eventType=-1;
    try {
      eventType=parser.getEventType();
    }
 catch (    XmlPullParserException xppe) {
    }
    String oneOf=null;
    if (names.length == 1) {
      oneOf="String_Node_Str" + names[0] + "String_Node_Str";
    }
 else {
      oneOf="String_Node_Str";
      for (      String name : names) {
        oneOf+="String_Node_Str" + name + "String_Node_Str";
      }
      oneOf+="String_Node_Str";
    }
    String foundInstead="String_Node_Str";
    if (eventType == KXmlParser.END_TAG) {
      foundInstead="String_Node_Str" + parser.getName() + "String_Node_Str";
    }
 else     if (eventType == KXmlParser.START_TAG) {
      foundInstead="String_Node_Str" + parser.getName() + "String_Node_Str";
    }
 else     if (eventType == KXmlParser.TEXT) {
      foundInstead="String_Node_Str" + parser.getText() + "String_Node_Str";
    }
 else {
      foundInstead="String_Node_Str";
    }
    throw new InvalidStructureException("String_Node_Str" + oneOf + foundInstead+ "String_Node_Str",parser);
  }
}
Program: 146765
Project: 146765
Buggy source:
public void serialize(DataInstance instance,TreeReference base) throws IOException {
  AbstractTreeElement root;
  if (base == null) {
    root=instance.getRoot();
  }
 else {
    root=instance.resolveReference(base);
  }
  serializer.startTag(root.getNamespace(),root.getName());
  for (int i=0; i < root.getNumChildren(); i++) {
    AbstractTreeElement childAt=root.getChildAt(i);
    serializeNode(childAt);
  }
  serializer.endTag(root.getNamespace(),root.getName());
}

Fixed version (ground truth):
public void serialize(DataInstance instance,TreeReference base) throws IOException {
  AbstractTreeElement root;
  if (base == null) {
    root=instance.getRoot();
  }
 else {
    root=instance.resolveReference(base);
  }
  serializer.startTag(root.getNamespace(),root.getName());
  for (int i=0; i < root.getNumChildren(); i++) {
    AbstractTreeElement childAt=root.getChildAt(i);
    serializeNode(childAt);
  }
  serializer.endTag(root.getNamespace(),root.getName());
  serializer.flush();
}
Program: 146767
Project: 146767
Buggy source:
public boolean equals(Object o){
  return (o instanceof PrefixTreeNode ? prefix.equals(((PrefixTreeNode)o).prefix) : false);
}

Fixed version (ground truth):
public boolean equals(Object o){
  return (o instanceof PrefixTreeNode ? ArrayUtilities.arraysEqual(prefix,0,((PrefixTreeNode)o).prefix,0) : false);
}
Program: 146771
Project: 146771
Buggy source:
public Vector getSingleStringAttributeVector(){
  Vector strings=new Vector();
  if (attributes == null || attributes.size() == 0)   return null;
 else {
    for (int i=0; i < this.attributes.size(); i++) {
      TreeElement attribute=attributes.elementAt(i);
      String value=getAttributeValue(attribute);
      if (attribute.namespace == null || attribute.namespace == "String_Node_Str")       strings.addElement(new String(attribute.getName() + "String_Node_Str" + value));
 else       strings.addElement(new String(attribute.namespace + "String_Node_Str" + attribute.getName()+ "String_Node_Str"+ value));
    }
    return strings;
  }
}

Fixed version (ground truth):
public Vector getSingleStringAttributeVector(){
  Vector strings=new Vector();
  if (attributes == null || attributes.size() == 0)   return null;
 else {
    for (int i=0; i < this.attributes.size(); i++) {
      TreeElement attribute=attributes.elementAt(i);
      String value=getAttributeValue(attribute);
      if (attribute.namespace == null || attribute.namespace.equals("String_Node_Str"))       strings.addElement(new String(attribute.getName() + "String_Node_Str" + value));
 else       strings.addElement(new String(attribute.namespace + "String_Node_Str" + attribute.getName()+ "String_Node_Str"+ value));
    }
    return strings;
  }
}
Program: 146772
Project: 146772
Buggy source:
public K intern(K k){
synchronized (this) {
    int hash=k.hashCode();
    K nk=retrieve(hash);
    if (nk == null) {
      register(hash,k);
      return k;
    }
    if (k.equals(nk)) {
      return nk;
    }
    return k;
  }
}

Fixed version (ground truth):
public K intern(K k){
synchronized (this) {
    int hash=k.hashCode();
    K nk=retrieve(hash);
    if (nk == null) {
      register(hash,k);
      return k;
    }
    if (k.equals(nk)) {
      return nk;
    }
 else {
      System.out.println("String_Node_Str" + nk.toString() + "String_Node_Str"+ k);
    }
    return k;
  }
}
Program: 146774
Project: 146774
Buggy source:
public void register(int key,K item){
synchronized (this) {
    currentTable.put(DataUtil.integer(key),new WeakReference(item));
  }
}

Fixed version (ground truth):
public void register(int key,K item){
synchronized (this) {
    currentTable.put(DataUtil.integer(key),new WeakReference(item));
    totalAdditions++;
  }
}
Program: 146775
Project: 146775
Buggy source:
public int hashCode(){
  int code=this.axis | this.test | (this.name == null ? 0 : this.name.hashCode())| (this.literal == null ? 0 : this.literal.hashCode())| (this.namespace == null ? 0 : this.namespace.hashCode());
  for (  XPathExpression xpe : predicates) {
    code|=xpe.hashCode();
  }
  return code;
}

Fixed version (ground truth):
public int hashCode(){
  int code=this.axis ^ this.test ^ (this.name == null ? 0 : this.name.hashCode())^ (this.literal == null ? 0 : this.literal.hashCode())^ (this.namespace == null ? 0 : this.namespace.hashCode());
  for (  XPathExpression xpe : predicates) {
    code^=xpe.hashCode();
  }
  return code;
}
Program: 146776
Project: 146776
Buggy source:
private void buildIndex(){
synchronized (metadataAccessLock) {
    MemoryUtils.stopTerning();
    try {
      metaDataIndex=new Hashtable();
      if (!hasMetaData) {
        return;
      }
      String[] fields=getFields();
      for (int k=0; k < fields.length; k++) {
        metaDataIndex.put(fields[k],new Hashtable());
      }
      IStorageIterator i=iterate();
      int records=this.getNumRecords();
      Hashtable[] metadata=new Hashtable[records];
      int[] recordIds=new int[records];
      for (int j=0; j < records; ++j) {
        metadata[j]=new Hashtable(fields.length);
        for (        String field : fields) {
          metadata[j].put(field,"String_Node_Str");
        }
      }
      int count=0;
      IMetaData obj;
      while (i.hasMore()) {
        recordIds[count]=i.nextID();
        count++;
      }
      for (int index=0; index < recordIds.length; ++index) {
        obj=(IMetaData)read(recordIds[index]);
        copyHT(metadata[index],getMetaData(obj,fields),fields);
        obj=null;
        System.gc();
      }
      for (int index=0; index < recordIds.length; ++index) {
        indexMetaData(recordIds[index],metadata[index]);
      }
    }
  finally {
      MemoryUtils.revertTerning();
    }
  }
}

Fixed version (ground truth):
private void buildIndex(){
synchronized (metadataAccessLock) {
    try {
      metaDataIndex=new Hashtable();
      if (!hasMetaData) {
        return;
      }
      String[] fields=getFields();
      for (int k=0; k < fields.length; k++) {
        metaDataIndex.put(fields[k],new Hashtable());
      }
      IStorageIterator i=iterate();
      int records=this.getNumRecords();
      Hashtable[] metadata=new Hashtable[records];
      int[] recordIds=new int[records];
      for (int j=0; j < records; ++j) {
        metadata[j]=new Hashtable(fields.length);
        for (        String field : fields) {
          metadata[j].put(field,"String_Node_Str");
        }
      }
      int count=0;
      IMetaData obj;
      while (i.hasMore()) {
        recordIds[count]=i.nextID();
        count++;
      }
      for (int index=0; index < recordIds.length; ++index) {
        obj=(IMetaData)read(recordIds[index]);
        copyHT(metadata[index],getMetaData(obj,fields),fields);
        obj=null;
        System.gc();
      }
      for (int index=0; index < recordIds.length; ++index) {
        indexMetaData(recordIds[index],metadata[index]);
      }
    }
  finally {
    }
  }
}
Program: 146777
Project: 146777
Buggy source:
public static void startStateWithLoadingScreen(State state,ProgressIndicator indicator){
  final State s=state;
  loading.cancelLoading();
  loading=new LoadingScreenThread(display);
  loading.startLoading(indicator);
  if (display != null) {
    CrashHandler.expire(display.getCurrent());
  }
  new HandledThread(new Runnable(){
    public void run(){
      s.start();
    }
  }
).start();
}

Fixed version (ground truth):
public static void startStateWithLoadingScreen(State state,ProgressIndicator indicator){
  final State s=state;
  loading.cancelLoading();
  loading=new LoadingScreenThread(display);
  loading.startLoading(indicator);
  if (display != null) {
    CrashHandler.expire(display.getCurrent());
  }
  new HandledThread(new Runnable(){
    public void run(){
      String className=s.getClass().getName();
      MemoryUtils.printMemoryTest(className.substring(Math.max(0,className.lastIndexOf('.'))));
      s.start();
    }
  }
).start();
}
Program: 146778
Project: 146778
Buggy source:
public void run(){
  s.start();
}

Fixed version (ground truth):
public void run(){
  String className=s.getClass().getName();
  MemoryUtils.printMemoryTest(className.substring(Math.max(0,className.lastIndexOf('.'))));
  s.start();
}
Program: 146779
Project: 146779
Buggy source:
public static void main(String argv[]){
  XFormValidatorGUI.instance=new XFormValidatorGUI();
}

Fixed version (ground truth):
public static void main(String argv[]){
  XFormValidatorGUI.instance=new XFormValidatorGUI();
  XFormUtils.setXFormParserFactory(new XFormParserFactory(interns));
}
Program: 146780
Project: 146780
Buggy source:
public TreeReference genericize(){
  TreeReference genericRef=clone();
  for (int i=0; i < genericRef.size(); i++) {
    genericRef.setMultiplicity(i,INDEX_UNBOUND);
  }
  return genericRef;
}

Fixed version (ground truth):
public TreeReference genericize(){
  TreeReference genericRef=clone();
  for (int i=0; i < genericRef.size(); i++) {
    if (genericRef.getMultiplicity(i) > -1 || genericRef.getMultiplicity(i) == INDEX_TEMPLATE) {
      genericRef.setMultiplicity(i,INDEX_UNBOUND);
    }
  }
  return genericRef;
}
Program: 146787
Project: 146787
Buggy source:
/** 
 * This just calls the resource's installer directly, but also handles the logic around attempting retries if applicable
 * @throws UnfullfilledRequirementsException 
 */
private boolean installResource(Resource r,ResourceLocation location,Reference ref,ResourceTable table,CommCareInstance instance,boolean upgrade) throws UnresolvedResourceException, UnfullfilledRequirementsException {
  UnreliableSourceException aFailure=null;
  for (int i=0; i < 1 + this.numberOfLossyRetries; ++i) {
    try {
      return r.getInstaller().install(r,location,ref,table,instance,upgrade);
    }
 catch (    UnreliableSourceException use) {
      System.out.println("String_Node_Str");
      aFailure=use;
      Logger.log("String_Node_Str","String_Node_Str" + (i + 1) + "String_Node_Str"+ (numberOfLossyRetries + 1)+ "String_Node_Str"+ ref.getURI()+ "String_Node_Str"+ use.getMessage());
      if (use.shouldBreak()) {
        break;
      }
    }
  }
  if (aFailure != null) {
    throw aFailure;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * This just calls the resource's installer directly, but also handles the logic around attempting retries if applicable
 * @throws UnfullfilledRequirementsException 
 */
private boolean installResource(Resource r,ResourceLocation location,Reference ref,ResourceTable table,CommCareInstance instance,boolean upgrade) throws UnresolvedResourceException, UnfullfilledRequirementsException {
  UnreliableSourceException aFailure=null;
  for (int i=0; i < 1 + this.numberOfLossyRetries; ++i) {
    try {
      return r.getInstaller().install(r,location,ref,table,instance,upgrade);
    }
 catch (    UnreliableSourceException use) {
      aFailure=use;
      Logger.log("String_Node_Str","String_Node_Str" + (i + 1) + "String_Node_Str"+ (numberOfLossyRetries + 1)+ "String_Node_Str"+ ref.getURI()+ "String_Node_Str"+ use.getMessage());
    }
  }
  if (aFailure != null) {
    throw aFailure;
  }
  return false;
}
Program: 146788
Project: 146788
Buggy source:
public UnreliableSourceException(Resource r,String message,boolean shouldBreak){
  super(r,message);
  this.shouldBreak=shouldBreak;
}

Fixed version (ground truth):
public UnreliableSourceException(Resource r,String message){
  super(r,message);
}
Program: 146789
Project: 146789
Buggy source:
public boolean install(Resource r,ResourceLocation location,Reference ref,ResourceTable table,CommCareInstance instance,boolean upgrade) throws UnresolvedResourceException {
  InputStream incoming=null;
  try {
    if (location.getAuthority() == Resource.RESOURCE_AUTHORITY_CACHE) {
      return false;
    }
 else {
      incoming=ref.getStream();
      if (incoming == null) {
        return false;
      }
      FormDef formDef=new XFormParser(new InputStreamReader(incoming,"String_Node_Str")).parse();
      if (formDef == null) {
        return false;
      }
      if (upgrade) {
        formDef.getInstance().schema=formDef.getInstance().schema + "String_Node_Str";
        storage().write(formDef);
        cacheLocation=formDef.getID();
        table.commit(r,Resource.RESOURCE_STATUS_UPGRADE);
      }
 else {
        storage().write(formDef);
        cacheLocation=formDef.getID();
        table.commit(r,Resource.RESOURCE_STATUS_INSTALLED);
      }
      return true;
    }
  }
 catch (  StorageFullException e) {
    e.printStackTrace();
    return false;
  }
catch (  IOException e) {
    throw new UnreliableSourceException(r,e.getMessage());
  }
catch (  XFormParseException xpe) {
    System.out.println("String_Node_Str");
    throw new UnreliableSourceException(r,xpe.getMessage(),true);
  }
 finally {
    try {
      if (incoming != null) {
        incoming.close();
      }
    }
 catch (    IOException e) {
    }
  }
}

Fixed version (ground truth):
public boolean install(Resource r,ResourceLocation location,Reference ref,ResourceTable table,CommCareInstance instance,boolean upgrade) throws UnresolvedResourceException {
  InputStream incoming=null;
  try {
    if (location.getAuthority() == Resource.RESOURCE_AUTHORITY_CACHE) {
      return false;
    }
 else {
      incoming=ref.getStream();
      if (incoming == null) {
        return false;
      }
      FormDef formDef=new XFormParser(new InputStreamReader(incoming,"String_Node_Str")).parse();
      if (formDef == null) {
        return false;
      }
      if (upgrade) {
        formDef.getInstance().schema=formDef.getInstance().schema + "String_Node_Str";
        storage().write(formDef);
        cacheLocation=formDef.getID();
        table.commit(r,Resource.RESOURCE_STATUS_UPGRADE);
      }
 else {
        storage().write(formDef);
        cacheLocation=formDef.getID();
        table.commit(r,Resource.RESOURCE_STATUS_INSTALLED);
      }
      return true;
    }
  }
 catch (  StorageFullException e) {
    e.printStackTrace();
    return false;
  }
catch (  IOException e) {
    throw new UnreliableSourceException(r,e.getMessage());
  }
catch (  XFormParseException xpe) {
    throw new UnresolvedResourceException(r,"String_Node_Str" + ref.getURI() + "String_Node_Str"+ xpe.getMessage(),true);
  }
 finally {
    try {
      if (incoming != null) {
        incoming.close();
      }
    }
 catch (    IOException e) {
    }
  }
}
Program: 146790
Project: 146790
Buggy source:
private static Recalculate buildCalculate(String xpath,IDataReference contextRef){
  XPathConditional calc;
  try {
    calc=new XPathConditional(xpath);
  }
 catch (  XPathSyntaxException xse) {
    System.err.println("String_Node_Str" + xpath + "String_Node_Str");
    return null;
  }
  Recalculate r=new Recalculate(calc,FormInstance.unpackReference(contextRef));
  return r;
}

Fixed version (ground truth):
private static Recalculate buildCalculate(String xpath,IDataReference contextRef) throws XPathSyntaxException {
  XPathConditional calc=new XPathConditional(xpath);
  Recalculate r=new Recalculate(calc,FormInstance.unpackReference(contextRef));
  return r;
}
Program: 146793
Project: 146793
Buggy source:
public Vector<TreeReference> evalNodeset(DataInstance model,EvaluationContext evalContext){
  if (expr instanceof XPathPathExpr) {
    return ((XPathPathExpr)expr).eval(model,evalContext).nodes;
  }
 else {
    throw new FatalException("String_Node_Str");
  }
}

Fixed version (ground truth):
public Vector<TreeReference> evalNodeset(DataInstance model,EvaluationContext evalContext){
  if (expr instanceof XPathPathExpr) {
    return ((XPathPathExpr)expr).eval(model,evalContext).getReferences();
  }
 else {
    throw new FatalException("String_Node_Str");
  }
}
Program: 146794
Project: 146794
Buggy source:
private void performEvaluation(){
synchronized (evaluated) {
    if (evaluated.booleanValue()) {
      return;
    }
    nodes=ec.expandReference(unExpandedRef);
    for (int i=0; i < nodes.size(); i++) {
      if (!instance.resolveReference((TreeReference)nodes.elementAt(i)).isRelevant()) {
        nodes.removeElementAt(i);
        i--;
      }
    }
    evaluated=true;
  }
}

Fixed version (ground truth):
private void performEvaluation(){
synchronized (evaluated) {
    if (evaluated.booleanValue()) {
      return;
    }
    Vector<TreeReference> nodes=ec.expandReference(unExpandedRef);
    for (int i=0; i < nodes.size(); i++) {
      if (!instance.resolveReference((TreeReference)nodes.elementAt(i)).isRelevant()) {
        nodes.removeElementAt(i);
        i--;
      }
    }
    this.setReferences(nodes);
    evaluated=true;
  }
}
Program: 146795
Project: 146795
Buggy source:
/** 
 * @return The value represented by this xpath. Can only be evaluated when this xpath represents exactly onereference, or when it represents 0 references after a filtering operation (a reference which _could_ have existed, but didn't, rather than a reference which could not represent a real node).
 */
public Object unpack(){
synchronized (evaluated) {
    if (evaluated.booleanValue()) {
      return super.unpack();
    }
    int size=unExpandedRef.size();
    boolean safe=true;
    ;
    for (int i=0; i < size; ++i) {
      if (unExpandedRef.getPredicate(i) != null) {
        safe=false;
        break;
      }
      int mult=unExpandedRef.getMultiplicity(i);
      if (!(mult >= 0 || mult == TreeReference.INDEX_UNBOUND)) {
        safe=false;
        break;
      }
    }
    if (!safe) {
      performEvaluation();
      return super.unpack();
    }
    return XPathPathExpr.getRefValue(instance,ec,unExpandedRef);
  }
}

Fixed version (ground truth):
/** 
 * @return The value represented by this xpath. Can only be evaluated when this xpath represents exactly onereference, or when it represents 0 references after a filtering operation (a reference which _could_ have existed, but didn't, rather than a reference which could not represent a real node).
 */
public Object unpack(){
synchronized (evaluated) {
    if (evaluated.booleanValue()) {
      return super.unpack();
    }
    int size=unExpandedRef.size();
    boolean safe=true;
    ;
    for (int i=0; i < size; ++i) {
      if (unExpandedRef.getPredicate(i) != null) {
        safe=false;
        break;
      }
      int mult=unExpandedRef.getMultiplicity(i);
      if (!(mult >= 0 || mult == TreeReference.INDEX_UNBOUND)) {
        safe=false;
        break;
      }
    }
    if (!safe) {
      performEvaluation();
      return super.unpack();
    }
    try {
      return XPathPathExpr.getRefValue(instance,ec,unExpandedRef);
    }
 catch (    XPathException xpe) {
      performEvaluation();
      return super.unpack();
    }
  }
}
Program: 146797
Project: 146797
Buggy source:
public Boolean parse() throws InvalidStructureException, IOException, XmlPullParserException, UnfullfilledRequirementsException {
  try {
    String rootName=parser.getName();
    String itemString=parser.getAttributeValue(null,"String_Node_Str");
    int itemNumber=-1;
    if (itemString != null) {
      try {
        itemNumber=Integer.parseInt(itemString);
      }
 catch (      NumberFormatException e) {
        itemNumber=0;
      }
      rListener.setTotalForms(itemNumber);
    }
    parseBlock(rootName);
  }
  finally {
    try {
      is.close();
    }
 catch (    IOException ioe) {
    }
  }
  if (errors.size() == 0) {
    return Boolean.TRUE;
  }
 else {
    return Boolean.FALSE;
  }
}

Fixed version (ground truth):
public Boolean parse() throws InvalidStructureException, IOException, XmlPullParserException, UnfullfilledRequirementsException {
  try {
    String rootName=parser.getName();
    if (requiredRootEnvelope != null && !requiredRootEnvelope.equals(rootName)) {
      throw new InvalidStructureException("String_Node_Str" + rootName + "String_Node_Str"+ requiredRootEnvelope+ "String_Node_Str",parser);
    }
    String itemString=parser.getAttributeValue(null,"String_Node_Str");
    int itemNumber=-1;
    if (itemString != null) {
      try {
        itemNumber=Integer.parseInt(itemString);
      }
 catch (      NumberFormatException e) {
        itemNumber=0;
      }
      rListener.setTotalForms(itemNumber);
    }
    parseBlock(rootName);
  }
  finally {
    try {
      is.close();
    }
 catch (    IOException ioe) {
    }
  }
  if (errors.size() == 0) {
    return Boolean.TRUE;
  }
 else {
    return Boolean.FALSE;
  }
}
Program: 146798
Project: 146798
Buggy source:
/** 
 * Get all of the elements which will need to be evaluated (in order) when the triggerable is fired.
 * @param t
 */
public void fillTriggeredElements(Triggerable t,Vector<Triggerable> destination){
  if (t.canCascade()) {
    for (int j=0; j < t.getTargets().size(); j++) {
      TreeReference target=(TreeReference)t.getTargets().elementAt(j);
      Vector<TreeReference> updatedNodes=new Vector<TreeReference>();
      updatedNodes.addElement(target);
      if (t.isCascadingToChildren()) {
        addChildrenOfReference(target,updatedNodes);
      }
      for (      TreeReference ref : updatedNodes) {
        Vector<Triggerable> triggered=(Vector<Triggerable>)triggerIndex.get(ref);
        if (triggered != null) {
          for (int k=0; k < triggered.size(); k++) {
            Triggerable u=(Triggerable)triggered.elementAt(k);
            if (!destination.contains(u))             destination.addElement(u);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Get all of the elements which will need to be evaluated (in order) when the triggerable is fired.
 * @param t
 */
public void fillTriggeredElements(Triggerable t,Vector<Triggerable> destination){
  if (t.canCascade()) {
    for (int j=0; j < t.getTargets().size(); j++) {
      TreeReference target=(TreeReference)t.getTargets().elementAt(j);
      Vector<TreeReference> updatedNodes=new Vector<TreeReference>();
      updatedNodes.addElement(target);
      if (t.isCascadingToChildren()) {
        addChildrenOfReference(target,updatedNodes);
      }
      for (      TreeReference ref : updatedNodes) {
        Vector<Triggerable> triggered=(Vector<Triggerable>)triggerIndex.get(ref.hasPredicates() ? ref.removePredicates() : ref);
        if (triggered != null) {
          for (int k=0; k < triggered.size(); k++) {
            Triggerable u=(Triggerable)triggered.elementAt(k);
            if (!destination.contains(u))             destination.addElement(u);
          }
        }
      }
    }
  }
}
Program: 146799
Project: 146799
Buggy source:
public int hashCode(){
  int hash=(new Integer(refLevel)).hashCode();
  for (int i=0; i < size(); i++) {
    Integer mult=DataUtil.integer(getMultiplicity(i));
    if (i == 0 && mult.intValue() == INDEX_UNBOUND)     mult=DataUtil.integer(0);
    hash^=getName(i).hashCode();
    hash^=mult.hashCode();
  }
  return hash;
}

Fixed version (ground truth):
public int hashCode(){
  int hash=(new Integer(refLevel)).hashCode();
  for (int i=0; i < size(); i++) {
    Integer mult=DataUtil.integer(getMultiplicity(i));
    if (i == 0 && mult.intValue() == INDEX_UNBOUND)     mult=DataUtil.integer(0);
    hash^=getName(i).hashCode();
    hash^=mult.hashCode();
    Vector<XPathExpression> predicates=this.getPredicate(i);
    if (predicates == null) {
      continue;
    }
    int val=0;
    for (    XPathExpression xpe : predicates) {
      hash^=val;
      hash^=xpe.hashCode();
      ++val;
    }
  }
  return hash;
}