nus-yam/ex-repair huggingface dataset:
Program: 146965
Project: 146965
Buggy source:
public TransactionParser getParser(String name,String namespace,KXmlParser parser){
  if (name.toLowerCase().equals("String_Node_Str")) {
    return new CaseXmlParser(parser,caseTallies);
  }
 else   if (name.toLowerCase().equals("String_Node_Str")) {
    return new UserXmlParser(parser);
  }
 else   if (name.equalsIgnoreCase("String_Node_Str")) {
    return new TransactionParser<String>(parser,"String_Node_Str",null){
      public void commit(      String parsed) throws IOException {
      }
      public String parse() throws XmlPullParserException, IOException {
        String restoreID=parser.nextText().trim();
        restoreIDWrapper[0]=restoreID;
        return restoreID;
      }
    }
;
  }
  return null;
}

Fixed version (ground truth):
public TransactionParser getParser(String name,String namespace,KXmlParser parser){
  if (name.toLowerCase().equals("String_Node_Str")) {
    return new CaseXmlParser(parser,caseTallies,!noPartial);
  }
 else   if (name.toLowerCase().equals("String_Node_Str")) {
    return new UserXmlParser(parser);
  }
 else   if (name.equalsIgnoreCase("String_Node_Str")) {
    return new TransactionParser<String>(parser,"String_Node_Str",null){
      public void commit(      String parsed) throws IOException {
      }
      public String parse() throws XmlPullParserException, IOException {
        String restoreID=parser.nextText().trim();
        restoreIDWrapper[0]=restoreID;
        return restoreID;
      }
    }
;
  }
  return null;
}
Program: 146967
Project: 146967
Buggy source:
protected void setProperties(){
  PropertyManager._().addRules(new JavaRosaPropertyRules());
  PropertyManager._().addRules(new CommCareProperties());
  PropertyManager._().addRules(new FormManagerProperties());
  PropertyUtils.initializeProperty("String_Node_Str",PropertyUtils.genGUID(25));
  PropertyUtils.initializeProperty(CommCareProperties.IS_FIRST_RUN,CommCareProperties.FIRST_RUN_YES);
  PropertyUtils.initializeProperty(FormManagerProperties.EXTRA_KEY_FORMAT,FormManagerProperties.EXTRA_KEY_LANGUAGE_CYCLE);
  PropertyUtils.initializeProperty(CommCareProperties.ENTRY_MODE,CommCareProperties.ENTRY_MODE_QUICK);
  PropertyManager._().setProperty(CommCareProperties.COMMCARE_VERSION,CommCareUtil.getVersion());
  PropertyUtils.initializeProperty(CommCareProperties.DEPLOYMENT_MODE,CommCareProperties.DEPLOY_DEFAULT);
}

Fixed version (ground truth):
protected void setProperties(){
  PropertyManager._().addRules(new JavaRosaPropertyRules());
  PropertyManager._().addRules(new CommCareProperties());
  PropertyManager._().addRules(new FormManagerProperties());
  PropertyUtils.initializeProperty("String_Node_Str",PropertyUtils.genGUID(25));
  PropertyUtils.initializeProperty(CommCareProperties.IS_FIRST_RUN,CommCareProperties.FIRST_RUN_YES);
  PropertyManager._().setProperty(CommCareProperties.COMMCARE_VERSION,CommCareUtil.getVersion());
  PropertyUtils.initializeProperty(CommCareProperties.DEPLOYMENT_MODE,CommCareProperties.DEPLOY_DEFAULT);
}
Program: 146968
Project: 146968
Buggy source:
private void postProfilePropertyInit(){
  PropertyUtils.initializeProperty(CommCareProperties.SEND_STYLE,CommCareProperties.SEND_STYLE_HTTP);
  PropertyUtils.initializeProperty(CommCareProperties.OTA_RESTORE_OFFLINE,"String_Node_Str");
  PropertyUtils.initializeProperty(CommCareProperties.RESTORE_TOLERANCE,CommCareProperties.REST_TOL_LOOSE);
  PropertyUtils.initializeProperty(CommCareProperties.DEMO_MODE,CommCareProperties.DEMO_ENABLED);
  PropertyUtils.initializeProperty(CommCareProperties.TETHER_MODE,CommCareProperties.TETHER_PUSH_ONLY);
}

Fixed version (ground truth):
private void postProfilePropertyInit(){
  PropertyUtils.initializeProperty(FormManagerProperties.EXTRA_KEY_FORMAT,FormManagerProperties.EXTRA_KEY_LANGUAGE_CYCLE);
  PropertyUtils.initializeProperty(CommCareProperties.ENTRY_MODE,CommCareProperties.ENTRY_MODE_QUICK);
  PropertyUtils.initializeProperty(CommCareProperties.SEND_STYLE,CommCareProperties.SEND_STYLE_HTTP);
  PropertyUtils.initializeProperty(CommCareProperties.OTA_RESTORE_OFFLINE,"String_Node_Str");
  PropertyUtils.initializeProperty(CommCareProperties.RESTORE_TOLERANCE,CommCareProperties.REST_TOL_LOOSE);
  PropertyUtils.initializeProperty(CommCareProperties.DEMO_MODE,CommCareProperties.DEMO_ENABLED);
  PropertyUtils.initializeProperty(CommCareProperties.TETHER_MODE,CommCareProperties.TETHER_PUSH_ONLY);
}
Program: 146969
Project: 146969
Buggy source:
public CaseXmlParser(KXmlParser parser,int[] tallies){
  super(parser,"String_Node_Str",null);
  this.tallies=tallies;
}

Fixed version (ground truth):
public CaseXmlParser(KXmlParser parser,int[] tallies,boolean acceptCreateOverwrites){
  super(parser,"String_Node_Str",null);
  this.tallies=tallies;
  this.acceptCreateOverwrites=acceptCreateOverwrites;
}
Program: 146971
Project: 146971
Buggy source:
public ReferralXmlParser(KXmlParser parser,String caseId,Date created){
  super(parser,"String_Node_Str",null);
  this.caseId=caseId;
  this.created=created;
}

Fixed version (ground truth):
public ReferralXmlParser(KXmlParser parser,String caseId,Date created,boolean acceptCreateOverwrites){
  super(parser,"String_Node_Str",null);
  this.caseId=caseId;
  this.created=created;
  this.acceptCreateOverwrites=acceptCreateOverwrites;
}
Program: 146973
Project: 146973
Buggy source:
/** 
 * Deletes the inner-most repeat that this node belongs to and returns the corresponding FormIndex. Behavior is currently undefined if you call this method on a node that is not contained within a repeat.
 * @param index
 * @return
 */
public FormIndex deleteRepeat(FormIndex index){
  Vector indexes=new Vector();
  Vector multiplicities=new Vector();
  Vector elements=new Vector();
  collapseIndex(index,indexes,multiplicities,elements);
  for (int i=elements.size() - 1; i >= 0; i--) {
    IFormElement e=(IFormElement)elements.elementAt(i);
    if (e instanceof GroupDef && ((GroupDef)e).getRepeat()) {
      break;
    }
 else {
      indexes.removeElementAt(i);
      multiplicities.removeElementAt(i);
      elements.removeElementAt(i);
    }
  }
  FormIndex newIndex=buildIndex(indexes,multiplicities,elements);
  TreeReference deleteRef=getChildInstanceRef(newIndex);
  TreeElement deleteElement=instance.resolveReference(deleteRef);
  TreeReference parentRef=deleteRef.getParentRef();
  TreeElement parentElement=instance.resolveReference(parentRef);
  int childMult=deleteElement.getMult();
  parentElement.removeChild(deleteElement);
  for (int i=0; i < parentElement.getNumChildren(); i++) {
    TreeElement child=parentElement.getChildAt(i);
    if (child.getMult() > childMult) {
      child.setMult(child.getMult() - 1);
    }
  }
  triggerTriggerables(parentRef);
  return newIndex;
}

Fixed version (ground truth):
/** 
 * Deletes the inner-most repeat that this node belongs to and returns the corresponding FormIndex. Behavior is currently undefined if you call this method on a node that is not contained within a repeat.
 * @param index
 * @return
 */
public FormIndex deleteRepeat(FormIndex index){
  Vector indexes=new Vector();
  Vector multiplicities=new Vector();
  Vector elements=new Vector();
  collapseIndex(index,indexes,multiplicities,elements);
  for (int i=elements.size() - 1; i >= 0; i--) {
    IFormElement e=(IFormElement)elements.elementAt(i);
    if (e instanceof GroupDef && ((GroupDef)e).getRepeat()) {
      break;
    }
 else {
      indexes.removeElementAt(i);
      multiplicities.removeElementAt(i);
      elements.removeElementAt(i);
    }
  }
  FormIndex newIndex=buildIndex(indexes,multiplicities,elements);
  TreeReference deleteRef=getChildInstanceRef(newIndex);
  TreeElement deleteElement=instance.resolveReference(deleteRef);
  TreeReference parentRef=deleteRef.getParentRef();
  TreeElement parentElement=instance.resolveReference(parentRef);
  int childMult=deleteElement.getMult();
  parentElement.removeChild(deleteElement);
  for (int i=0; i < parentElement.getNumChildren(); i++) {
    TreeElement child=parentElement.getChildAt(i);
    if (child.getMult() > childMult) {
      child.setMult(child.getMult() - 1);
    }
  }
  triggerTriggerables(deleteRef);
  return newIndex;
}
Program: 146974
Project: 146974
Buggy source:
/** 
 * Add a Condition to the form's Collection.
 * @param condition the condition to be set
 */
public Triggerable addTriggerable(Triggerable t){
  int existingIx=triggerables.indexOf(t);
  if (existingIx >= 0) {
    return (Triggerable)triggerables.elementAt(existingIx);
  }
 else {
    triggerables.addElement(t);
    triggerablesInOrder=false;
    Vector triggers=t.getTriggers();
    for (int i=0; i < triggers.size(); i++) {
      TreeReference trigger=(TreeReference)triggers.elementAt(i);
      if (!triggerIndex.containsKey(trigger)) {
        triggerIndex.put(trigger,new Vector());
      }
      Vector triggered=(Vector)triggerIndex.get(trigger);
      if (!triggered.contains(t)) {
        triggered.addElement(t);
      }
    }
    if (t instanceof Condition) {
      Vector targets=t.getTargets();
      for (int i=0; i < targets.size(); i++) {
        TreeReference target=(TreeReference)targets.elementAt(i);
        if (instance.getTemplate(target) != null) {
          conditionRepeatTargetIndex.put(target,(Condition)t);
        }
      }
    }
    return t;
  }
}

Fixed version (ground truth):
/** 
 * Add a Condition to the form's Collection.
 * @param condition the condition to be set
 */
public Triggerable addTriggerable(Triggerable t){
  int existingIx=triggerables.indexOf(t);
  if (existingIx >= 0) {
    return (Triggerable)triggerables.elementAt(existingIx);
  }
 else {
    triggerables.addElement(t);
    triggerablesInOrder=false;
    Vector triggers=t.getTriggers();
    for (int i=0; i < triggers.size(); i++) {
      TreeReference trigger=(TreeReference)triggers.elementAt(i);
      if (!triggerIndex.containsKey(trigger)) {
        triggerIndex.put(trigger,new Vector());
      }
      Vector triggered=(Vector)triggerIndex.get(trigger);
      if (!triggered.contains(t)) {
        triggered.addElement(t);
      }
    }
    return t;
  }
}
Program: 146976
Project: 146976
Buggy source:
/** 
 */
public FormDef(){
  setID(-1);
  setChildren(null);
  triggerables=new Vector();
  triggerablesInOrder=true;
  triggerIndex=new Hashtable();
  conditionRepeatTargetIndex=new Hashtable();
  setEvaluationContext(new EvaluationContext());
  outputFragments=new Vector();
}

Fixed version (ground truth):
/** 
 */
public FormDef(){
  setID(-1);
  setChildren(null);
  triggerables=new Vector();
  triggerablesInOrder=true;
  triggerIndex=new Hashtable();
  setEvaluationContext(new EvaluationContext());
  outputFragments=new Vector();
}
Program: 146977
Project: 146977
Buggy source:
private static void parseInstance(FormDef f,Element e){
  TreeElement root=buildInstanceStructure(e,null);
  FormInstance instanceModel=new FormInstance(root);
  instanceModel.setName(f.getTitle());
  Vector usedAtts=new Vector();
  usedAtts.addElement("String_Node_Str");
  usedAtts.addElement("String_Node_Str");
  String schema=e.getNamespace();
  if (schema != null && schema.length() > 0 && !schema.equals(defaultNamespace)) {
    instanceModel.schema=schema;
  }
  instanceModel.formVersion=e.getAttributeValue(null,"String_Node_Str");
  instanceModel.uiVersion=e.getAttributeValue(null,"String_Node_Str");
  loadNamespaces(e,instanceModel);
  processRepeats(instanceModel);
  verifyBindings(f,instanceModel);
  applyInstanceProperties(instanceModel);
  loadInstanceData(e,root,f);
  checkDependencyCycles(f);
  f.finalizeTriggerables();
  f.setInstance(instanceModel);
  if (XFormUtils.showUnusedAttributeWarning(e,usedAtts)) {
    System.out.println(XFormUtils.unusedAttWarning(e,usedAtts));
  }
}

Fixed version (ground truth):
private static void parseInstance(FormDef f,Element e){
  TreeElement root=buildInstanceStructure(e,null);
  FormInstance instanceModel=new FormInstance(root);
  instanceModel.setName(f.getTitle());
  Vector usedAtts=new Vector();
  usedAtts.addElement("String_Node_Str");
  usedAtts.addElement("String_Node_Str");
  String schema=e.getNamespace();
  if (schema != null && schema.length() > 0 && !schema.equals(defaultNamespace)) {
    instanceModel.schema=schema;
  }
  instanceModel.formVersion=e.getAttributeValue(null,"String_Node_Str");
  instanceModel.uiVersion=e.getAttributeValue(null,"String_Node_Str");
  loadNamespaces(e,instanceModel);
  processRepeats(instanceModel);
  verifyBindings(f,instanceModel);
  applyInstanceProperties(instanceModel);
  loadInstanceData(e,root,f);
  checkDependencyCycles(f);
  f.setInstance(instanceModel);
  f.finalizeTriggerables();
  if (XFormUtils.showUnusedAttributeWarning(e,usedAtts)) {
    System.out.println(XFormUtils.unusedAttWarning(e,usedAtts));
  }
}
Program: 146978
Project: 146978
Buggy source:
public void start(){
  view=new CommCareSuiteView(m.getName().evaluate());
  view.setCommandListener(this);
  configView();
  J2MEDisplay.setView(view);
}

Fixed version (ground truth):
public void start(){
  view=new CommCareSuiteView(m.getName().evaluate());
  view.setCommandListener(this);
  J2MEDisplay.setView(view);
}
Program: 146979
Project: 146979
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 1;
    }
    public int getMinorVersion(){
      return 1;
    }
    public int getMajorVersion(){
      return 1;
    }
    public int getMinorVersion(){
      return 0;
    }
  }
;
  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);
}

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 1;
    }
    public int getMinorVersion(){
      return 1;
    }
  }
;
  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);
}
Program: 146980
Project: 146980
Buggy source:
public int getMinorVersion(){
  return 0;
}

Fixed version (ground truth):
public int getMinorVersion(){
  return 1;
}
Program: 146981
Project: 146981
Buggy source:
public FormIndex descendIntoRepeat(FormIndex index,int repIndex){
  Vector indexes=new Vector();
  Vector multiplicities=new Vector();
  Vector elements=new Vector();
  if (!index.isInForm()) {
    throw new RuntimeException("String_Node_Str");
  }
  collapseIndex(index,indexes,multiplicities,elements);
  if (!(elements.lastElement() instanceof GroupDef) || !((GroupDef)elements.lastElement()).getRepeat()) {
    throw new RuntimeException("String_Node_Str");
  }
  TreeElement node=instance.resolveReference(getChildInstanceRef(elements,multiplicities));
  String name=node.getName();
  int numRepetitions=node.getParent().getChildMultiplicity(name);
  if (repIndex < 0 || repIndex >= numRepetitions) {
    throw new RuntimeException("String_Node_Str");
  }
  multiplicities.setElementAt(new Integer(repIndex),multiplicities.size() - 1);
  return buildIndex(indexes,multiplicities,elements);
}

Fixed version (ground truth):
public FormIndex descendIntoRepeat(FormIndex index,int repIndex){
  Vector indexes=new Vector();
  Vector multiplicities=new Vector();
  Vector elements=new Vector();
  if (!index.isInForm()) {
    throw new RuntimeException("String_Node_Str");
  }
  collapseIndex(index,indexes,multiplicities,elements);
  if (!(elements.lastElement() instanceof GroupDef) || !((GroupDef)elements.lastElement()).getRepeat()) {
    throw new RuntimeException("String_Node_Str");
  }
  TreeElement node=instance.resolveReference(getChildInstanceRef(elements,multiplicities));
  int numRepetitions=0;
  if (node != null) {
    String name=node.getName();
    numRepetitions=node.getParent().getChildMultiplicity(name);
  }
  if (repIndex < 0 || repIndex >= numRepetitions) {
    throw new RuntimeException("String_Node_Str");
  }
  multiplicities.setElementAt(new Integer(repIndex),multiplicities.size() - 1);
  return buildIndex(indexes,multiplicities,elements);
}
Program: 146982
Project: 146982
Buggy source:
public Vector<String> getAvailableRepetitions(FormIndex index){
  Vector indexes=new Vector();
  Vector multiplicities=new Vector();
  Vector elements=new Vector();
  collapseIndex(index,indexes,multiplicities,elements);
  TreeElement node=instance.resolveReference(getChildInstanceRef(elements,multiplicities));
  String name=node.getName();
  int numRepetitions=node.getParent().getChildMultiplicity(name);
  Vector<String> reps=new Vector<String>();
  for (int i=0; i < numRepetitions; i++) {
    reps.addElement("String_Node_Str" + (i + 1));
  }
  return reps;
}

Fixed version (ground truth):
public Vector<String> getAvailableRepetitions(FormIndex index){
  Vector indexes=new Vector();
  Vector multiplicities=new Vector();
  Vector elements=new Vector();
  collapseIndex(index,indexes,multiplicities,elements);
  TreeElement node=instance.resolveReference(getChildInstanceRef(elements,multiplicities));
  int numRepetitions=0;
  if (node != null) {
    String name=node.getName();
    numRepetitions=node.getParent().getChildMultiplicity(name);
  }
  Vector<String> reps=new Vector<String>();
  for (int i=0; i < numRepetitions; i++) {
    reps.addElement("String_Node_Str" + (i + 1));
  }
  return reps;
}
Program: 146983
Project: 146983
Buggy source:
/** 
 * Attempts to save the answer at the specified FormIndex into the datamodel.
 * @param index
 * @param data
 * @return OK if save was successful, error if a constraint was violated.
 */
public int answerQuestion(FormIndex index,IAnswerData data){
  QuestionDef q=model.getQuestionPrompt(index).getQuestion();
  if (model.getEvent() != FormEntryController.EVENT_QUESTION) {
    throw new RuntimeException("String_Node_Str");
  }
  TreeElement element=model.getTreeElement(index);
  boolean complexQuestion=q.isComplex();
  boolean hasConstraints=false;
  if (element.required && data == null) {
    return ANSWER_REQUIRED_BUT_EMPTY;
  }
 else   if (!complexQuestion && !model.getForm().evaluateConstraint(index.getReference(),data)) {
    return ANSWER_CONSTRAINT_VIOLATED;
  }
 else   if (!complexQuestion) {
    commitAnswer(element,index,data);
    return ANSWER_OK;
  }
 else   if (complexQuestion && hasConstraints) {
    throw new RuntimeException("String_Node_Str");
  }
 else {
    try {
      model.getForm().copyItemsetAnswer(q,element,data);
    }
 catch (    InvalidReferenceException ire) {
      ire.printStackTrace();
      throw new RuntimeException("String_Node_Str" + ire.getMessage());
    }
    return ANSWER_OK;
  }
}

Fixed version (ground truth):
/** 
 * Attempts to save the answer at the specified FormIndex into the datamodel.
 * @param index
 * @param data
 * @return OK if save was successful, error if a constraint was violated.
 */
public int answerQuestion(FormIndex index,IAnswerData data){
  QuestionDef q=model.getQuestionPrompt(index).getQuestion();
  if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) {
    throw new RuntimeException("String_Node_Str");
  }
  TreeElement element=model.getTreeElement(index);
  boolean complexQuestion=q.isComplex();
  boolean hasConstraints=false;
  if (element.required && data == null) {
    return ANSWER_REQUIRED_BUT_EMPTY;
  }
 else   if (!complexQuestion && !model.getForm().evaluateConstraint(index.getReference(),data)) {
    return ANSWER_CONSTRAINT_VIOLATED;
  }
 else   if (!complexQuestion) {
    commitAnswer(element,index,data);
    return ANSWER_OK;
  }
 else   if (complexQuestion && hasConstraints) {
    throw new RuntimeException("String_Node_Str");
  }
 else {
    try {
      model.getForm().copyItemsetAnswer(q,element,data);
    }
 catch (    InvalidReferenceException ire) {
      ire.printStackTrace();
      throw new RuntimeException("String_Node_Str" + ire.getMessage());
    }
    return ANSWER_OK;
  }
}
Program: 146985
Project: 146985
Buggy source:
public void start(){
  J2MEDisplay.setView(view);
}

Fixed version (ground truth):
public void start(){
  view=new CommCareSuiteView(m.getName().evaluate());
  view.setCommandListener(this);
  configView();
  J2MEDisplay.setView(view);
}
Program: 146986
Project: 146986
Buggy source:
public Text parse() throws InvalidStructureException, IOException, XmlPullParserException {
  Vector<Text> texts=new Vector<Text>();
  checkNode("String_Node_Str");
  int entryLevel=parser.getDepth();
  try {
    parser.next();
  }
 catch (  XmlPullParserException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
  while (parser.getDepth() > entryLevel) {
    Text t=parseBody();
    if (t != null) {
      texts.addElement(t);
    }
  }
  if (texts.size() == 1) {
    return texts.elementAt(0);
  }
 else {
    Text c=Text.CompositeText(texts);
    return c;
  }
}

Fixed version (ground truth):
public Text parse() throws InvalidStructureException, IOException, XmlPullParserException {
  Vector<Text> texts=new Vector<Text>();
  checkNode("String_Node_Str");
  int entryLevel=parser.getDepth();
  try {
    parser.next();
  }
 catch (  XmlPullParserException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
  while (parser.getDepth() > entryLevel || parser.getEventType() == KXmlParser.TEXT) {
    Text t=parseBody();
    if (t != null) {
      texts.addElement(t);
    }
  }
  if (texts.size() == 1) {
    return texts.elementAt(0);
  }
 else {
    Text c=Text.CompositeText(texts);
    return c;
  }
}
Program: 146987
Project: 146987
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 1;
    }
    public int getMinorVersion(){
      return 1;
    }
  }
;
  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);
}

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 1;
    }
    public int getMinorVersion(){
      return 1;
    }
    public int getMajorVersion(){
      return 1;
    }
    public int getMinorVersion(){
      return 0;
    }
  }
;
  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);
}
Program: 146988
Project: 146988
Buggy source:
public int getMinorVersion(){
  return 1;
}

Fixed version (ground truth):
public int getMinorVersion(){
  return 0;
}
Program: 146989
Project: 146989
Buggy source:
/** 
 * @param args
 */
public static void main(String[] args){
  if (args.length < 1) {
    printformat();
    System.exit(-1);
  }
  if (args[0].equals("String_Node_Str")) {
    if (args.length < 2) {
      printvalidateformat();
      System.exit(-1);
    }
    CommCareConfigEngine engine=new CommCareConfigEngine(System.out);
    engine.addLocalFileResource(args[1]);
    engine.resolveTable();
    engine.validateResources();
    engine.describeApplication();
    System.exit(0);
  }
}

Fixed version (ground truth):
/** 
 * @param args
 */
public static void main(String[] args){
  if (args.length < 1) {
    printformat();
    System.exit(-1);
  }
  if (args[0].equals("String_Node_Str")) {
    if (args.length < 2) {
      printvalidateformat();
      System.exit(-1);
    }
    CommCareConfigEngine engine=new CommCareConfigEngine(System.out);
    engine.addLocalFileResource(args[1]);
    if (args.length > 2) {
      if (args[2].equals("String_Node_Str")) {
      }
 else {
        engine.addJarResources(args[2]);
      }
    }
 else {
      engine.addJarResources("String_Node_Str" + File.separator + "String_Node_Str"+ File.separator+ "String_Node_Str");
      engine.addJarResources("String_Node_Str" + File.separator + "String_Node_Str"+ File.separator+ "String_Node_Str"+ File.separator+ "String_Node_Str"+ File.separator+ "String_Node_Str"+ File.separator+ "String_Node_Str");
    }
    engine.resolveTable();
    engine.validateResources();
    engine.describeApplication();
    System.exit(0);
  }
}
Program: 146990
Project: 146990
Buggy source:
public JavaFileReference(String localPart,String uri){
  this.localPart=localPart;
  this.uri=uri;
}

Fixed version (ground truth):
public JavaFileReference(String localPart,String uri,String authority){
  this.localPart=localPart;
  this.uri=uri;
  this.authority=authority;
}
Program: 146991
Project: 146991
Buggy source:
public String getURI(){
  return "String_Node_Str" + uri;
}

Fixed version (ground truth):
public String getURI(){
  return "String_Node_Str" + authority + "String_Node_Str"+ uri;
}
Program: 146992
Project: 146992
Buggy source:
protected Reference factory(String terminal,String URI){
  return new JavaFileReference(localRoot,terminal);
}

Fixed version (ground truth):
protected Reference factory(String terminal,String URI){
  if (authority != null) {
    return new JavaFileReference(localRoot,terminal,authority);
  }
 else {
    return new JavaFileReference(localRoot,terminal);
  }
}
Program: 146993
Project: 146993
Buggy source:
public JavaFileRoot(String localRoot){
  super(new String[]{"String_Node_Str"});
  this.localRoot=localRoot;
}

Fixed version (ground truth):
public JavaFileRoot(String[] uriRoots,String localRoot){
  super(uriRoots);
  if (uriRoots.length == 1) {
    authority=uriRoots[0];
  }
  this.localRoot=localRoot;
}
Program: 146994
Project: 146994
Buggy source:
/** 
 * Convenience method Get longText form of text for THIS element (if available)  !!Falls back to default form if 'long' form does not exist.!! Use getSpecialFormQuestionText() if you want short form only.
 * @return longText form 
 */
public String getLongText(){
  String returnText=getSpecialFormQuestionText(getTextID(),TEXT_FORM_LONG);
  if (returnText == null)   returnText=getQuestionText(getTextID());
  return returnText;
}

Fixed version (ground truth):
/** 
 * Convenience method Get longText form of text for THIS element (if available)  !!Falls back to default form if 'long' form does not exist.!! Use getSpecialFormQuestionText() if you want short form only.
 * @return longText form 
 */
public String getLongText(){
  return getQuestionText(getTextID());
}
Program: 146995
Project: 146995
Buggy source:
/** 
 * Same as getSpecialFormQuestionText(String textID,String form) except that the textID defaults to the textID of the current element.
 * @param form - special text form of textID you're trying to retrieve. 
 * @return Special Form Question Text. <code>null</code> if no text for this element exists (with the specified special form).
 * @throws RunTimeException if this method is called on an element that is NOT a QuestionDef
 */
public String getSpecialFormQuestionText(String form){
  if (!(getFormElement() instanceof QuestionDef))   throw new RuntimeException("String_Node_Str");
  return getSpecialFormQuestionText(getTextID(),form);
}

Fixed version (ground truth):
/** 
 * Same as getSpecialFormQuestionText(String textID,String form) except that the textID defaults to the textID of the current element.
 * @param form - special text form of textID you're trying to retrieve. 
 * @return Special Form Question Text. <code>null</code> if no text for this element exists (with the specified special form).
 * @throws RunTimeException if this method is called on an element that is NOT a QuestionDef
 */
public String getSpecialFormQuestionText(String form){
  return getSpecialFormQuestionText(getTextID(),form);
}
Program: 146996
Project: 146996
Buggy source:
/** 
 * Convenience method Get shortText form of text for THIS element (if available)  !!Falls back to default form if 'short' form does not exist.!! Use getSpecialFormQuestionText() if you want short form only.
 * @return shortText form 
 */
public String getShortText(){
  String returnText=getSpecialFormQuestionText(getTextID(),TEXT_FORM_SHORT);
  if (returnText == null)   returnText=getQuestionText(getTextID());
  return returnText;
}

Fixed version (ground truth):
/** 
 * Convenience method Get shortText form of text for THIS element (if available)  !!Falls back to default form if 'short' form does not exist.!! Use getSpecialFormQuestionText() if you want short form only.
 * @return shortText form 
 */
public String getShortText(){
  String returnText=getSpecialFormQuestionText(getTextID(),TEXT_FORM_SHORT);
  if (returnText == null)   returnText=getSpecialFormQuestionText(null);
  return returnText;
}
Program: 146997
Project: 146997
Buggy source:
/** 
 * This method is generally used to retrieve special forms for a  (select or 1select) item, e.g. "audio", "video", etc.
 * @param sel - The Item whose text you're trying to retrieve.
 * @param form - Special text form of Item you're trying to retrieve. 
 * @return Special Form Text. <code>null</code> if no text for this element exists (with the specified special form).
 * @throws RunTimeException if this method is called on an element that is NOT a QuestionDef
 * @throws IllegalArgumentException if <code>sel == null</code>
 */
public String getSpecialFormSelectItemText(Selection sel,String form){
  if (!(getFormElement() instanceof QuestionDef))   throw new RuntimeException("String_Node_Str");
  if (sel == null)   throw new IllegalArgumentException("String_Node_Str");
  String textID=sel.choice.getTextID();
  if (textID == null || textID.equals("String_Node_Str"))   return null;
  String returnText=getIText(textID,form);
  return substituteStringArgs(returnText);
}

Fixed version (ground truth):
/** 
 * This method is generally used to retrieve special forms for a  (select or 1select) item, e.g. "audio", "video", etc.
 * @param sel - The Item whose text you're trying to retrieve.
 * @param form - Special text form of Item you're trying to retrieve. 
 * @return Special Form Text. <code>null</code> if no text for this element exists (with the specified special form).
 * @throws RunTimeException if this method is called on an element that is NOT a QuestionDef
 * @throws IllegalArgumentException if <code>sel == null</code>
 */
public String getSpecialFormSelectItemText(Selection sel,String form){
  if (sel == null)   throw new IllegalArgumentException("String_Node_Str");
  String textID=sel.choice.getTextID();
  if (textID == null || textID.equals("String_Node_Str"))   return null;
  String returnText=getIText(textID,form);
  return substituteStringArgs(returnText);
}
Program: 146998
Project: 146998
Buggy source:
public void visit(FormInstance tree){
  theXmlDoc=new Document();
  TreeElement root=tree.resolveReference(rootRef);
  for (int i=0; i < root.getNumChildren(); i++) {
    TreeElement childAt=root.getChildAt(i);
  }
  if (root != null) {
    theXmlDoc.addChild(Node.ELEMENT,serializeNode(root));
  }
  Element top=theXmlDoc.getElement(0);
  String[] prefixes=tree.getNamespacePrefixes();
  for (int i=0; i < prefixes.length; ++i) {
    top.setPrefix(prefixes[i],tree.getNamespaceURI(prefixes[i]));
  }
  if (tree.schema != null) {
    top.setNamespace(tree.schema);
    top.setPrefix("String_Node_Str",tree.schema);
  }
}

Fixed version (ground truth):
public void visit(FormInstance tree){
  theXmlDoc=new Document();
  TreeElement root=tree.resolveReference(rootRef);
  if (root == null) {
    root=tree.getRoot();
  }
  for (int i=0; i < root.getNumChildren(); i++) {
    TreeElement childAt=root.getChildAt(i);
  }
  if (root != null) {
    theXmlDoc.addChild(Node.ELEMENT,serializeNode(root));
  }
  Element top=theXmlDoc.getElement(0);
  String[] prefixes=tree.getNamespacePrefixes();
  for (int i=0; i < prefixes.length; ++i) {
    top.setPrefix(prefixes[i],tree.getNamespaceURI(prefixes[i]));
  }
  if (tree.schema != null) {
    top.setNamespace(tree.schema);
    top.setPrefix("String_Node_Str",tree.schema);
  }
}
Program: 147000
Project: 147000
Buggy source:
public void clearLogs(){
  Vector ids=new Vector();
  IStorageIterator li=logStorage.iterate();
  while (li.hasMore()) {
    ids.addElement(new Integer(li.nextID()));
  }
  for (int i=0; i < ids.size(); i++) {
    int id=((Integer)ids.elementAt(i)).intValue();
    logStorage.remove(id);
  }
}

Fixed version (ground truth):
public void clearLogs(){
synchronized (logStorage) {
    if (!checkStorage()) {
      return;
    }
    Vector ids=new Vector();
    IStorageIterator li=logStorage.iterate();
    while (li.hasMore()) {
      ids.addElement(new Integer(li.nextID()));
    }
    for (int i=0; i < ids.size(); i++) {
      int id=((Integer)ids.elementAt(i)).intValue();
      logStorage.remove(id);
    }
  }
}
Program: 147001
Project: 147001
Buggy source:
public void log(String type,String message,Date logDate){
  LogEntry log=new LogEntry(type,message,logDate);
  try {
    logStorage.add(log);
  }
 catch (  StorageFullException e) {
    throw new RuntimeException("String_Node_Str");
  }
}

Fixed version (ground truth):
public void log(String type,String message,Date logDate){
synchronized (logStorage) {
    LogEntry log=new LogEntry(type,message,logDate);
    try {
      logStorage.add(log);
    }
 catch (    StorageFullException e) {
      throw new RuntimeException("String_Node_Str");
    }
  }
}
Program: 147002
Project: 147002
Buggy source:
public boolean serializeLogs(IAtomicLogSerializer serializer){
  IStorageIterator li=logStorage.iterate();
  while (li.hasMore()) {
    if (!serializer.serializeLog((LogEntry)li.nextRecord()))     ;
    return false;
  }
  return true;
}

Fixed version (ground truth):
public boolean serializeLogs(IAtomicLogSerializer serializer){
synchronized (logStorage) {
    if (!checkStorage()) {
      return false;
    }
    IStorageIterator li=logStorage.iterate();
    while (li.hasMore()) {
      if (!serializer.serializeLog((LogEntry)li.nextRecord()))       ;
      return false;
    }
    return true;
  }
}
Program: 147003
Project: 147003
Buggy source:
public int logSize(){
  return logStorage.getNumRecords();
}

Fixed version (ground truth):
public int logSize(){
synchronized (logStorage) {
    if (!checkStorage()) {
      return -1;
    }
    return logStorage.getNumRecords();
  }
}
Program: 147004
Project: 147004
Buggy source:
public void clearLogs(){
  Vector ids=new Vector();
  IStorageIterator li=logStorage.iterate();
  while (li.hasMore()) {
    ids.addElement(new Integer(li.nextID()));
  }
  for (int i=0; i < ids.size(); i++) {
    int id=((Integer)ids.elementAt(i)).intValue();
    logStorage.remove(id);
  }
}

Fixed version (ground truth):
public void clearLogs(){
synchronized (logStorage) {
    if (!checkStorage()) {
      return;
    }
    Vector ids=new Vector();
    IStorageIterator li=logStorage.iterate();
    while (li.hasMore()) {
      ids.addElement(new Integer(li.nextID()));
    }
    for (int i=0; i < ids.size(); i++) {
      int id=((Integer)ids.elementAt(i)).intValue();
      logStorage.remove(id);
    }
  }
}
Program: 147005
Project: 147005
Buggy source:
public void log(String type,String message,Date logDate){
  LogEntry log=new LogEntry(type,message,logDate);
  try {
    logStorage.add(log);
  }
 catch (  StorageFullException e) {
    throw new RuntimeException("String_Node_Str");
  }
}

Fixed version (ground truth):
public void log(String type,String message,Date logDate){
synchronized (logStorage) {
    LogEntry log=new LogEntry(type,message,logDate);
    try {
      logStorage.add(log);
    }
 catch (    StorageFullException e) {
      throw new RuntimeException("String_Node_Str");
    }
  }
}
Program: 147006
Project: 147006
Buggy source:
public boolean serializeLogs(IAtomicLogSerializer serializer){
  IStorageIterator li=logStorage.iterate();
  while (li.hasMore()) {
    if (!serializer.serializeLog((LogEntry)li.nextRecord()))     ;
    return false;
  }
  return true;
}

Fixed version (ground truth):
public boolean serializeLogs(IAtomicLogSerializer serializer){
synchronized (logStorage) {
    if (!checkStorage()) {
      return false;
    }
    IStorageIterator li=logStorage.iterate();
    while (li.hasMore()) {
      if (!serializer.serializeLog((LogEntry)li.nextRecord()))       ;
      return false;
    }
    return true;
  }
}
Program: 147007
Project: 147007
Buggy source:
public int logSize(){
  return logStorage.getNumRecords();
}

Fixed version (ground truth):
public int logSize(){
synchronized (logStorage) {
    if (!checkStorage()) {
      return -1;
    }
    return logStorage.getNumRecords();
  }
}
Program: 147008
Project: 147008
Buggy source:
private static String formatDateColloquial(DateFields f){
  return intPad(f.day,2) + "String_Node_Str" + intPad(f.month,2)+ "String_Node_Str"+ (new Integer(f.year)).toString().substring(2,4);
}

Fixed version (ground truth):
private static String formatDateColloquial(DateFields f){
  String year=new Integer(f.year).toString();
  if (year.length() == 4) {
    year=year.substring(2,4);
  }
  return intPad(f.day,2) + "String_Node_Str" + intPad(f.month,2)+ "String_Node_Str"+ year;
}
Program: 147009
Project: 147009
Buggy source:
/** 
 * convert the data object returned by the xpath expression into an IAnswerData suitable for storage in the FormInstance
 */
private static IAnswerData wrapData(Object val,int dataType){
  if ((val instanceof String && ((String)val).length() == 0) || (val instanceof Double && ((Double)val).isNaN())) {
    return null;
  }
  if (Constants.DATATYPE_BOOLEAN == dataType || val instanceof Boolean) {
    boolean b;
    if (val instanceof Boolean) {
      b=((Boolean)val).booleanValue();
    }
 else     if (val instanceof Double) {
      Double d=(Double)val;
      b=Math.abs(d.doubleValue()) > 1.0e-12 && !Double.isNaN(d);
    }
 else     if (val instanceof String) {
      String s=(String)val;
      b=s.length() > 0;
    }
 else {
      throw new RuntimeException("String_Node_Str");
    }
    return new BooleanData(b);
  }
 else   if (val instanceof Double) {
    double d=((Double)val).doubleValue();
    boolean isIntegral=Math.abs(d - (int)d) < 1.0e-9;
    if (Constants.DATATYPE_INTEGER == dataType || isIntegral) {
      return new IntegerData((int)d);
    }
 else {
      return new DecimalData(d);
    }
  }
 else   if (val instanceof String) {
    return new StringData((String)val);
  }
 else   if (val instanceof Date) {
    return new DateData((Date)val);
  }
 else {
    throw new RuntimeException("String_Node_Str" + val.getClass().getName());
  }
}

Fixed version (ground truth):
/** 
 * convert the data object returned by the xpath expression into an IAnswerData suitable for storage in the FormInstance
 */
private static IAnswerData wrapData(Object val,int dataType){
  if ((val instanceof String && ((String)val).length() == 0) || (val instanceof Double && ((Double)val).isNaN())) {
    return null;
  }
  if (Constants.DATATYPE_BOOLEAN == dataType || val instanceof Boolean) {
    boolean b;
    if (val instanceof Boolean) {
      b=((Boolean)val).booleanValue();
    }
 else     if (val instanceof Double) {
      Double d=(Double)val;
      b=Math.abs(d.doubleValue()) > 1.0e-12 && !Double.isNaN(d);
    }
 else     if (val instanceof String) {
      String s=(String)val;
      b=s.length() > 0;
    }
 else {
      throw new RuntimeException("String_Node_Str");
    }
    return new BooleanData(b);
  }
 else   if (val instanceof Double) {
    double d=((Double)val).doubleValue();
    boolean isIntegral=Math.abs(d - (int)d) < 1.0e-9;
    if (Constants.DATATYPE_INTEGER == dataType || isIntegral) {
      return new IntegerData((int)d);
    }
 else {
      return new DecimalData(d);
    }
  }
 else   if (val instanceof String) {
    return new StringData((String)val);
  }
 else   if (val instanceof Date) {
    return (dataType == Constants.DATATYPE_DATE_TIME ? new DateTimeData((Date)val) : new DateData((Date)val));
  }
 else {
    throw new RuntimeException("String_Node_Str" + val.getClass().getName());
  }
}
Program: 147010
Project: 147010
Buggy source:
public void setValue(Object o){
  if (o == null) {
    throw new NullPointerException("String_Node_Str");
  }
  d=new Date(((Date)o).getTime());
}

Fixed version (ground truth):
public void setValue(Object o){
  if (o == null) {
    throw new NullPointerException("String_Node_Str");
  }
  d=DateUtils.roundDate((Date)o);
}
Program: 147011
Project: 147011
Buggy source:
private static String formatDateColloquial(DateFields f){
  return intPad(f.day,2) + "String_Node_Str" + intPad(f.month,2)+ "String_Node_Str"+ (new Integer(f.year)).toString().substring(2,4);
}

Fixed version (ground truth):
private static String formatDateColloquial(DateFields f){
  String year=new Integer(f.year).toString();
  if (year.length() == 4) {
    year=year.substring(2,4);
  }
  return intPad(f.day,2) + "String_Node_Str" + intPad(f.month,2)+ "String_Node_Str"+ year;
}
Program: 147012
Project: 147012
Buggy source:
public Object getSortKey(String fieldKey){
  if (fieldKey.equals("String_Node_Str")) {
    return new Integer(this.getRecordID());
  }
 else {
    try {
      return getShortFields()[Integer.valueOf(fieldKey).intValue()];
    }
 catch (    NumberFormatException nfe) {
      nfe.printStackTrace();
      throw new RuntimeException("String_Node_Str" + fieldKey);
    }
  }
}

Fixed version (ground truth):
public Object getSortKey(String fieldKey){
  if (fieldKey.equals("String_Node_Str")) {
    return new Integer(this.getRecordID());
  }
 else {
    try {
      return getShortFields()[Integer.valueOf(fieldKey).intValue() - 1];
    }
 catch (    NumberFormatException nfe) {
      nfe.printStackTrace();
      throw new RuntimeException("String_Node_Str" + fieldKey);
    }
  }
}
Program: 147013
Project: 147013
Buggy source:
public Object getSortKey(String fieldKey){
  if (fieldKey.equals("String_Node_Str")) {
    return new Integer(this.getRecordID());
  }
 else {
    try {
      return getShortFields()[Integer.valueOf(fieldKey).intValue()];
    }
 catch (    NumberFormatException nfe) {
      nfe.printStackTrace();
      throw new RuntimeException("String_Node_Str" + fieldKey);
    }
  }
}

Fixed version (ground truth):
public Object getSortKey(String fieldKey){
  if (fieldKey.equals("String_Node_Str")) {
    return new Integer(this.getRecordID());
  }
 else {
    try {
      return getShortFields()[Integer.valueOf(fieldKey).intValue() - 1];
    }
 catch (    NumberFormatException nfe) {
      nfe.printStackTrace();
      throw new RuntimeException("String_Node_Str" + fieldKey);
    }
  }
}
Program: 147014
Project: 147014
Buggy source:
protected String getFormOrDefault(String textID,String form){
  String t=null;
  if (textID == null) {
    return this.getText(null,null);
  }
  try {
    t=getText(textID,form);
  }
 catch (  NoLocalizedTextException nlte) {
    System.out.println("String_Node_Str" + form + "String_Node_Str"+ textID+ "String_Node_Str");
    t=getDefaultText(textID);
  }
  return t;
}

Fixed version (ground truth):
protected String getFormOrDefault(String textID,String form){
  String t=null;
  if (textID == null) {
    return this.getText(null,null);
  }
  try {
    t=getText(textID,form);
  }
 catch (  NoLocalizedTextException nlte) {
    System.out.println("String_Node_Str" + form + "String_Node_Str"+ textID+ "String_Node_Str");
    t=getDefaultText(textID);
  }
catch (  IllegalArgumentException iae) {
    System.out.println("String_Node_Str" + textID + "String_Node_Str");
    t=getDefaultText(textID);
  }
  return t;
}
Program: 147015
Project: 147015
Buggy source:
/** 
 * Convenience method Get shortText form of text for THIS element (if available) 
 * @return shortText form 
 */
public String getShortText(){
  return getFormOrDefault(getTextID(),TEXT_FORM_SHORT);
}

Fixed version (ground truth):
/** 
 * Convenience method System.out.println("Warning, Short text form requested for ["+textID+"] but doesn't exist. (Falling back to Default form)."); t = getDefaultText(textID); }catch(IllegalArgumentException iae){ Get shortText form of text for THIS element (if available) 
 * @return shortText form 
 */
public String getShortText(){
  return getFormOrDefault(getTextID(),TEXT_FORM_SHORT);
}