nus-yam/ex-repair huggingface dataset:
Program: 4871
Project: 4871
Buggy source:
/** 
 * Scans all the shared directories recursively and finds files that have .mp3 extension, and adds them to a hashmap keyed by hashes. <p>  Also creates another map that stores the hash to File of non mp3 files
 */
private void createFileToHashMaps(){
  SettingsManager man=SettingsManager.instance();
  ArrayList dirs=new ArrayList(Arrays.asList(man.getDirectories()));
  int k=0;
  while (k < dirs.size()) {
    File currDir=(File)dirs.get(k);
    k++;
    String[] subFiles=currDir.list();
    int z=subFiles.length;
    for (int j=0; j < z; j++) {
      File f=new File(currDir,subFiles[j]);
      if (f.isDirectory())       dirs.add(f);
    }
    File[] files=getSharedFiles(currDir);
    int size=0;
    if (files != null)     size=files.length;
    for (int i=0; i < size; i++) {
      String name="String_Node_Str";
      String hash="String_Node_Str";
      try {
        name=files[i].getCanonicalPath();
        hash=new String(LimeXMLUtils.hashFile(files[i]));
      }
 catch (      Exception e) {
        continue;
      }
      writeToMap(files[i],hash);
    }
  }
}

Fixed version (ground truth):
/** 
 * Scans all the shared directories recursively and finds files that have .mp3 extension, and adds them to a hashmap keyed by hashes. <p>  Also creates another map that stores the hash to File of non mp3 files
 */
private void createFileToHashMaps(){
  SettingsManager man=SettingsManager.instance();
  ArrayList dirs=new ArrayList(Arrays.asList(man.getDirectories()));
  int k=0;
  while (k < dirs.size() && !loadThreadInterrupted()) {
    File currDir=(File)dirs.get(k);
    k++;
    String[] subFiles=currDir.list();
    int z=subFiles.length;
    for (int j=0; j < z; j++) {
      File f=new File(currDir,subFiles[j]);
      if (f.isDirectory())       dirs.add(f);
    }
    File[] files=getSharedFiles(currDir);
    int size=0;
    if (files != null)     size=files.length;
    for (int i=0; i < size && !loadThreadInterrupted(); i++) {
      String name="String_Node_Str";
      String hash="String_Node_Str";
      try {
        name=files[i].getCanonicalPath();
        hash=new String(LimeXMLUtils.hashFile(files[i]));
      }
 catch (      Exception e) {
        continue;
      }
      writeToMap(files[i],hash);
    }
  }
}
Program: 4873
Project: 4873
Buggy source:
/** 
 * Sets the name of the jar file to load on startup, which is read in from the properties file by RunLime.
 * @param jarName the name of the jar file to load
 */
public void setJarName(final String jarName){
  setStringValue(JAR_NAME,jarName);
}

Fixed version (ground truth):
/** 
 * Sets the name of the jar file to load on startup, which is read in from the properties file by RunLime.
 * @param jarName the name of the jar file to load
 */
public void setJarName(final String jarName){
  setStringValue(JAR_NAME,jarName);
  setClasspath(jarName);
}
Program: 4874
Project: 4874
Buggy source:
/** 
 * Sets the classpath for legacy RunLime.jars.
 * @param classpath the classpath to set
 */
public void setClasspath(final String classpath){
  setStringValue(CLASSPATH,classpath);
}

Fixed version (ground truth):
/** 
 * Sets the classpath for legacy RunLime.jars.
 * @param classpath the classpath to set
 */
private void setClasspath(final String classpath){
  setStringValue(CLASSPATH,classpath);
  setJarName(classpath);
}
Program: 4875
Project: 4875
Buggy source:
/** 
 * Sets the name of the jar file to load on startup, which is read in from the properties file by RunLime.
 * @param jarName the name of the jar file to load
 */
public void setJarName(final String jarName){
  setStringValue(JAR_NAME,jarName);
  setStringValue(CLASSPATH,jarName);
}

Fixed version (ground truth):
/** 
 * Sets the name of the jar file to load on startup, which is read in from the properties file by RunLime.
 * @param jarName the name of the jar file to load
 */
public void setJarName(final String jarName){
  setStringValue(JAR_NAME,jarName);
}
Program: 4878
Project: 4878
Buggy source:
/** 
 * Checks to see if the specified date string is valid, according to our interpretation.  First, we are requiring date formats of the  form specified at: http://www.w3.org/TR/NOTE-datetime, a subset of  ISO 8601.  In addition to this, we require that the date at least specify the day of the month.  If it does not do this, it is so  general that it is useless for our purposes.
 * @param date the date string to validate
 * @return <tt>true</tt> if the string represents a valid date according to our critetia, <tt>false</tt> otherwise
 */
private static boolean isValidDate(final String date){
  int length=date.length();
  final String DASH="String_Node_Str";
  final String COLON="String_Node_Str";
  if (length < 10)   return false;
  if ((length != 10) && (length != 17) && (length != 20)&& (length != 22)) {
    return false;
  }
  if (!date.startsWith("String_Node_Str")) {
    return false;
  }
  int firstDashIndex=date.indexOf(DASH);
  int secondDashIndex=date.indexOf(DASH,firstDashIndex + 1);
  if ((firstDashIndex == -1) || (secondDashIndex == -1)) {
    return false;
  }
  if (length == 10)   return true;
  int firstColonIndex=date.indexOf(COLON);
  int secondColonIndex=date.indexOf(COLON,firstColonIndex + 1);
  if ((firstColonIndex != 13) || (secondColonIndex != 16)) {
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Checks to see if the date specified in the given string is a valid date according to the date-time formate specified at:<p> http://www.w3.org/TR/NOTE-datetime
 * @param date the date to check
 * @return <tt>true</tt> if the date fits the standard, <tt>false</tt> otherwise
 */
private static boolean isValidDate(final String date){
  StringTokenizer dateTokenizer=new StringTokenizer(date,"String_Node_Str");
  if (dateTokenizer.countTokens() != 3) {
    return false;
  }
  String YYYYStr=dateTokenizer.nextToken();
  String MMStr=dateTokenizer.nextToken();
  String DDStr=dateTokenizer.nextToken();
  try {
    int YYYY=Integer.parseInt(YYYYStr);
    int MM=Integer.parseInt(MMStr);
    int DD=Integer.parseInt(DDStr);
    if (YYYY < 2001 || YYYY > 4000)     return false;
    if (MM < 1 || MM > 12)     return false;
    if (DD < 1 || DD > 31)     return false;
  }
 catch (  NumberFormatException e) {
    return false;
  }
  return true;
}
Program: 4879
Project: 4879
Buggy source:
/** 
 * Compares <tt>AlternateLocation</tt> instances by date.  This compares alternate locations by how "good" we think they are, based on their freshness.  So, an natural ordering will provide alternate locations from latest to earliest, as the more recent locations are the preferred locations.
 * @param obj the <tt>Object</tt> instance to be compared
 * @return  the value <tt>0</tt> if the argument is an <tt>AlternateLocation</tt> with a timestamp equal to this  <tt>AlternateLocation</tt>'s timestamp; a value less than <tt>0</tt>  if the argument is an <tt>AlternateLocation</tt> with a timestamp  before this <tt>AlternateLocation</tt>s timestamp; and a value greater  than <tt>0</tt> if the argument is an <tt>AlternateLocation</tt>  with a timestamp after the timestamp of this  <tt>AlternateLocation</tt>
 * @exception <tt>ClassCastException</tt> if the argument is not an<tt>AlternateLocation</tt> 
 * @see java.lang.Comparable
 */
public int compareTo(Object obj){
  if (equals(obj))   return 0;
  if (obj == this)   return 0;
  if (!(obj instanceof AlternateLocation))   return -1;
  AlternateLocation al=(AlternateLocation)obj;
  if (URL.equals(al.URL)) {
    return (this.TIME < al.TIME ? 1 : (this.TIME == al.TIME ? 0 : -1));
  }
  if (isTimestamped() && al.isTimestamped()) {
    return (this.TIME < al.TIME ? 1 : (this.TIME == al.TIME ? -1 : -1));
  }
  if (isTimestamped()) {
    return -1;
  }
  if (al.isTimestamped()) {
    return 1;
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Compares <tt>AlternateLocation</tt> instances by date.  This compares alternate locations by how "good" we think they are, based on their freshness.  So, an natural ordering will provide alternate locations from latest to earliest, as the more recent locations are the preferred locations.
 * @param obj the <tt>Object</tt> instance to be compared
 * @return  the value <tt>0</tt> if the argument is an <tt>AlternateLocation</tt> with a timestamp equal to this  <tt>AlternateLocation</tt>'s timestamp; a value less than <tt>0</tt>  if the argument is an <tt>AlternateLocation</tt> with a timestamp  before this <tt>AlternateLocation</tt>s timestamp; and a value greater  than <tt>0</tt> if the argument is an <tt>AlternateLocation</tt>  with a timestamp after the timestamp of this  <tt>AlternateLocation</tt>
 * @exception <tt>ClassCastException</tt> if the argument is not an<tt>AlternateLocation</tt> 
 * @see java.lang.Comparable
 */
public int compareTo(Object obj){
  if (equals(obj))   return 0;
  if (obj == this)   return 0;
  if (!(obj instanceof AlternateLocation))   return -1;
  AlternateLocation al=(AlternateLocation)obj;
  if (URL.equals(al.URL)) {
    return (this.TIME < al.TIME ? 1 : (this.TIME == al.TIME ? 0 : -1));
  }
  if (isTimestamped() && al.isTimestamped()) {
    if (this.TIME == al.TIME) {
      return URL.toString().compareTo(al.URL.toString());
    }
    return (this.TIME < al.TIME ? 1 : -1);
  }
  if (isTimestamped()) {
    return -1;
  }
  if (al.isTimestamped()) {
    return 1;
  }
  return -1;
}
Program: 4880
Project: 4880
Buggy source:
/** 
 * Creates a new <tt>AlternateLocation</tt> with the specified <tt>URL</tt> and <tt>Date</tt> timestamp.
 * @param url the <tt>URL</tt> for the <tt>AlternateLocation</tt>
 * @param date the <tt>Date</tt> timestamp for the <tt>AlternateLocation</tt>
 */
private AlternateLocation(final URL url,final Date date){
  this.URL=url;
  this.TIME=date.getTime();
  this.OUTPUT_DATE_TIME=AlternateLocation.convertDateToString(date);
}

Fixed version (ground truth):
/** 
 * Creates a new <tt>AlternateLocation</tt> with the specified <tt>URL</tt> and <tt>Date</tt> timestamp.
 * @param url the <tt>URL</tt> for the <tt>AlternateLocation</tt>
 * @param date the <tt>Date</tt> timestamp for the <tt>AlternateLocation</tt>
 */
private AlternateLocation(final URL url,final Date date){
  this.URL=url;
  this.TIME=date.getTime();
  if (TIME == 0) {
    this.OUTPUT_DATE_TIME=null;
  }
 else {
    this.OUTPUT_DATE_TIME=AlternateLocation.convertDateToString(date);
  }
}
Program: 4881
Project: 4881
Buggy source:
/** 
 * Parses out the timestamp string from the alternate location header string, throwing an exception if there is any error.
 * @param location the full alternate-location HTTP header string,as specified in HUGE v0.93
 * @return the date/time string from the the alternate locationheader, or <tt>null</tt> if the date/time string could not be extracted, is invalid, or does not exist
 */
private static String extractTimestamp(final String location){
  int dateIndex=getTimestampIndex(location);
  if (dateIndex == -1)   return null;
  String dateTimeString=location.substring(dateIndex).trim();
  if (AlternateLocation.isValidDate(dateTimeString)) {
    return dateTimeString;
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Parses out the timestamp string from the alternate location header string, throwing an exception if there is any error.
 * @param location the full alternate-location HTTP header string,as specified in HUGE v0.93
 * @return the date/time string from the the alternate locationheader, or <tt>null</tt> if the date/time string could not be extracted, is invalid, or does not exist
 */
private static String extractTimestamp(final String location){
  StringTokenizer st=new StringTokenizer(location);
  int numToks=st.countTokens();
  if (numToks != 2 && numToks != 3) {
    return null;
  }
 else {
    String curTok=null;
    for (int i=0; i < numToks; i++) {
      curTok=st.nextToken();
    }
    if (AlternateLocation.isValidTimestamp(curTok)) {
      return curTok;
    }
 else {
      return null;
    }
  }
}
Program: 4882
Project: 4882
Buggy source:
/** 
 * Removes the timestamp from an alternate location header.  This will remove the timestamp from an alternate location header string that  includes the header name, or from an alternate location string that only contains the alternate location header value.
 * @param locationHeader the string containing the full header, or onlythe header value
 * @return the same string as supplied in the <tt>locationHeader</tt> argument, but with the timestamp removed
 */
private static String removeTimestamp(final String locationHeader){
  int timestampIndex=getTimestampIndex(locationHeader);
  if (timestampIndex != -1) {
    return locationHeader.substring(0,timestampIndex);
  }
  return locationHeader.trim();
}

Fixed version (ground truth):
/** 
 * Removes the timestamp from an alternate location header.  This will remove the timestamp from an alternate location header string that  includes the header name, or from an alternate location string that only contains the alternate location header value.
 * @param locationHeader the string containing the full header, or onlythe header value
 * @return the same string as supplied in the <tt>locationHeader</tt> argument, but with the timestamp removed
 */
private static String removeTimestamp(final String locationHeader){
  StringTokenizer st=new StringTokenizer(locationHeader);
  int numToks=st.countTokens();
  if (numToks == 1 || numToks == 2 || numToks == 3) {
    return st.nextToken();
  }
 else {
    return null;
  }
}
Program: 4883
Project: 4883
Buggy source:
public List getCollectionList(){
  if (replyDocs != null)   return replyDocs;
  replyDocs=new ArrayList();
synchronized (mainMap) {
    Iterator iter=mainMap.keySet().iterator();
    while (iter.hasNext()) {
      Object hash=iter.next();
      Object doc=mainMap.get(hash);
      replyDocs.add(doc);
    }
  }
  return replyDocs;
}

Fixed version (ground truth):
public List getCollectionList(){
  List replyDocs=new ArrayList();
synchronized (mainMap) {
    Iterator iter=mainMap.keySet().iterator();
    while (iter.hasNext()) {
      Object hash=iter.next();
      Object doc=mainMap.get(hash);
      replyDocs.add(doc);
    }
  }
  return replyDocs;
}
Program: 4884
Project: 4884
Buggy source:
public synchronized int mp3ToDisk(String mp3FileName){
  boolean wrote=false;
  int mp3WriteState=-1;
  if (ripMP3XML(mp3FileName))   mp3WriteState=commitID3Data(mp3FileName);
  wrote=write();
  this.changedHash=null;
  this.editor=null;
  if (!wrote)   return RW_ERROR;
  return mp3WriteState;
}

Fixed version (ground truth):
public int mp3ToDisk(String mp3FileName){
  boolean wrote=false;
  int mp3WriteState=-1;
  Object[] output=ripMP3XML(mp3FileName);
  if (((Boolean)output[0]).booleanValue())   mp3WriteState=commitID3Data(mp3FileName,(String)output[1],(ID3Editor)output[2]);
  wrote=write();
  if (!wrote)   return RW_ERROR;
  return mp3WriteState;
}
Program: 4885
Project: 4885
Buggy source:
public void addReply(String hash,LimeXMLDocument replyDoc){
synchronized (mainMap) {
    mainMap.put(hash,replyDoc);
  }
  replyDocs=null;
}

Fixed version (ground truth):
public void addReply(String hash,LimeXMLDocument replyDoc){
synchronized (mainMap) {
    mainMap.put(hash,replyDoc);
  }
}
Program: 4886
Project: 4886
Buggy source:
private boolean ripMP3XML(String modifiedFile){
  if (!LimeXMLUtils.isMP3File(modifiedFile))   return false;
  try {
    String hash=new String(LimeXMLUtils.hashFile(new File(modifiedFile)));
    LimeXMLDocument doc=(LimeXMLDocument)mainMap.get(hash);
    String fName=doc.getIdentifier();
    if (LimeXMLUtils.isMP3File(modifiedFile)) {
      ID3Editor e=new ID3Editor();
      String xml=doc.getXMLStringWithIdentifier();
      e.removeID3Tags(xml);
      this.editor=e;
      this.changedHash=hash;
    }
    return true;
  }
 catch (  Exception e) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * @return A Object[] of size 3.  First object is a boolean indicatedwhether you should commit this ID3 to disk, second is the new hash (String) of the file, and third is the ID3Editor to use....
 */
private Object[] ripMP3XML(String modifiedFile){
  Object[] retObjs=new Object[3];
  retObjs[0]=new Boolean(false);
  if (!LimeXMLUtils.isMP3File(modifiedFile))   return retObjs;
  try {
    String hash=new String(LimeXMLUtils.hashFile(new File(modifiedFile)));
    LimeXMLDocument doc=null;
synchronized (mainMap) {
      doc=(LimeXMLDocument)mainMap.get(hash);
    }
    String fName=doc.getIdentifier();
    if (LimeXMLUtils.isMP3File(modifiedFile)) {
      ID3Editor e=new ID3Editor();
      String xml=doc.getXMLStringWithIdentifier();
      e.removeID3Tags(xml);
      retObjs[0]=new Boolean(true);
      retObjs[1]=hash;
      retObjs[2]=e;
    }
    return retObjs;
  }
 catch (  Exception e) {
    return retObjs;
  }
}
Program: 4887
Project: 4887
Buggy source:
/** 
 * Simply write() out the mainMap to disk. 
 */
public boolean write(){
  if (dataFile == null) {
    String fname=LimeXMLSchema.getDisplayString(schemaURI) + "String_Node_Str";
    LimeXMLProperties props=LimeXMLProperties.instance();
    String path=props.getXMLDocsDir();
    dataFile=new File(path,fname);
  }
  try {
    MapSerializer ms=new MapSerializer(dataFile,mainMap);
    ms.commit();
  }
 catch (  Exception e) {
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Simply write() out the mainMap to disk. 
 */
public boolean write(){
  if (dataFile == null) {
    String fname=LimeXMLSchema.getDisplayString(schemaURI) + "String_Node_Str";
    LimeXMLProperties props=LimeXMLProperties.instance();
    String path=props.getXMLDocsDir();
    dataFile=new File(path,fname);
  }
  try {
    MapSerializer ms=new MapSerializer(dataFile,mainMap);
synchronized (writeLock) {
      ms.commit();
    }
  }
 catch (  Exception e) {
    return false;
  }
  return true;
}
Program: 4888
Project: 4888
Buggy source:
/** 
 * @return the older document, which is being replaced. Can be null.
 */
public LimeXMLDocument replaceDoc(Object hash,LimeXMLDocument newDoc){
  LimeXMLDocument oldDoc=null;
synchronized (mainMap) {
    oldDoc=(LimeXMLDocument)mainMap.get(hash);
    mainMap.put(hash,newDoc);
  }
  replyDocs=null;
  return oldDoc;
}

Fixed version (ground truth):
/** 
 * @return the older document, which is being replaced. Can be null.
 */
public LimeXMLDocument replaceDoc(Object hash,LimeXMLDocument newDoc){
  LimeXMLDocument oldDoc=null;
synchronized (mainMap) {
    oldDoc=(LimeXMLDocument)mainMap.get(hash);
    mainMap.put(hash,newDoc);
  }
  return oldDoc;
}
Program: 4890
Project: 4890
Buggy source:
private void checkDocuments(Set hashSet,boolean mp3){
  Iterator iter=null;
  if (hashSet != null)   iter=hashSet.iterator();
  if (iter == null)   return;
  while (iter.hasNext()) {
    File file=(File)iter.next();
    String hash=metaFileManager.readFromMap(file);
    LimeXMLDocument doc;
synchronized (mainMap) {
      doc=(LimeXMLDocument)mainMap.get(hash);
    }
    if (doc == null)     continue;
    String actualName=null;
    try {
      actualName=file.getCanonicalPath();
    }
 catch (    IOException ioe) {
synchronized (mainMap) {
        mainMap.remove(hash);
      }
    }
    String identifier=doc.getIdentifier();
    if (!actualName.equalsIgnoreCase(identifier))     doc.setIdentifier(actualName);
  }
}

Fixed version (ground truth):
/** 
 * This method resolves any discrepancy between the identifier in the  LimeXMLDocument with the actual file name of the file the LimeXMLDocument refers to.
 */
private void checkDocuments(Map fileToHash,boolean mp3){
synchronized (fileToHash) {
    Iterator iter=fileToHash.keySet().iterator();
    if (iter == null)     return;
    while (iter.hasNext()) {
      File file=(File)iter.next();
      String hash=(String)fileToHash.get(file);
      LimeXMLDocument doc;
synchronized (mainMap) {
        doc=(LimeXMLDocument)mainMap.get(hash);
      }
      if (doc == null)       continue;
      String actualName=null;
      try {
        actualName=file.getCanonicalPath();
      }
 catch (      IOException ioe) {
synchronized (mainMap) {
          mainMap.remove(hash);
        }
      }
      String identifier=doc.getIdentifier();
      if (!actualName.equalsIgnoreCase(identifier))       doc.setIdentifier(actualName);
    }
  }
}
Program: 4891
Project: 4891
Buggy source:
public synchronized void addReplyWithCommit(File f,String hash,LimeXMLDocument replyDoc){
  String identifier="String_Node_Str";
  try {
    identifier=f.getCanonicalPath();
  }
 catch (  IOException e) {
  }
  replyDoc.setIdentifier(identifier);
  addReply(hash,replyDoc);
  try {
    if (audio)     mp3ToDisk(f.getCanonicalPath());
 else     write();
  }
 catch (  Exception ignored) {
  }
}

Fixed version (ground truth):
public void addReplyWithCommit(File f,String hash,LimeXMLDocument replyDoc){
  String identifier="String_Node_Str";
  try {
    identifier=f.getCanonicalPath();
  }
 catch (  IOException e) {
  }
  replyDoc.setIdentifier(identifier);
  addReply(hash,replyDoc);
  try {
    if (audio)     mp3ToDisk(f.getCanonicalPath());
 else     write();
  }
 catch (  Exception ignored) {
  }
}
Program: 4892
Project: 4892
Buggy source:
public synchronized boolean removeDoc(String hash){
  replyDocs=null;
  boolean found;
  Object val;
synchronized (mainMap) {
    val=mainMap.remove(hash);
    found=val == null ? false : true;
  }
  boolean written=false;
  if (found) {
    written=write();
  }
  if (!written && found) {
synchronized (mainMap) {
      mainMap.put(hash,val);
    }
  }
 else   if (found && written)   return true;
  return false;
}

Fixed version (ground truth):
public boolean removeDoc(String hash){
  boolean found;
  Object val;
synchronized (mainMap) {
    val=mainMap.remove(hash);
    found=val == null ? false : true;
  }
  boolean written=false;
  if (found) {
    written=write();
  }
  if (!written && found) {
synchronized (mainMap) {
      mainMap.put(hash,val);
    }
  }
 else   if (found && written)   return true;
  return false;
}
Program: 4893
Project: 4893
Buggy source:
private int commitID3Data(String mp3FileName){
  int retVal=this.editor.writeID3DataToDisk(mp3FileName);
  if (retVal != NORMAL)   return retVal;
  File file=new File(mp3FileName);
  String newHash=null;
  try {
    newHash=new String(LimeXMLUtils.hashFile(file));
  }
 catch (  Exception e) {
    retVal=HASH_FAILED;
    return retVal;
  }
synchronized (mainMap) {
    Object mainValue=mainMap.remove(changedHash);
    mainMap.put(newHash,mainValue);
  }
  metaFileManager.writeToMap(file,newHash);
  metaFileManager.handleChangedHash(changedHash,newHash,this);
  return retVal;
}

Fixed version (ground truth):
private int commitID3Data(String mp3FileName,String changedHash,ID3Editor editor){
  int retVal=editor.writeID3DataToDisk(mp3FileName);
  if (retVal != NORMAL)   return retVal;
  File file=new File(mp3FileName);
  String newHash=null;
  try {
    newHash=new String(LimeXMLUtils.hashFile(file));
  }
 catch (  Exception e) {
    retVal=HASH_FAILED;
    return retVal;
  }
synchronized (mainMap) {
    Object mainValue=mainMap.remove(changedHash);
    mainMap.put(newHash,mainValue);
  }
  metaFileManager.writeToMap(file,newHash);
  metaFileManager.handleChangedHash(changedHash,newHash,this);
  return retVal;
}
Program: 4895
Project: 4895
Buggy source:
/** 
 * Parses out the header value from the HTTP header string.
 * @return the header value for the specified full header string, or<tt>null</tt> if the value could not be extracted
 */
public static String extractHeaderValue(final String header){
  int index=header.indexOf("String_Node_Str");
  if (index == 0)   return null;
  return header.substring(index + 2).trim();
}

Fixed version (ground truth):
/** 
 * Parses out the header value from the HTTP header string.
 * @return the header value for the specified full header string, or<tt>null</tt> if the value could not be extracted
 */
public static String extractHeaderValue(final String header){
  int index=header.indexOf("String_Node_Str");
  if (index == 0)   return null;
  return header.substring(index + 1).trim();
}
Program: 4896
Project: 4896
Buggy source:
/** 
 * Returns whether or not the specified Namespace Specific String (NSS)  is a valid NSS.
 * @param nss the Namespace Specific String for a URN
 * @return <tt>true</tt> if the NSS is valid, <tt>false</tt> otherwise
 */
private static boolean isValidNamespaceSpecificString(final String nss){
  int length=NSS.length();
  if ((length != 32) && (length != 72)) {
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Returns whether or not the specified Namespace Specific String (NSS)  is a valid NSS.
 * @param nss the Namespace Specific String for a URN
 * @return <tt>true</tt> if the NSS is valid, <tt>false</tt> otherwise
 */
private static boolean isValidNamespaceSpecificString(final String nss){
  int length=nss.length();
  if ((length != 32) && (length != 72)) {
    return false;
  }
  return true;
}
Program: 4898
Project: 4898
Buggy source:
/** 
 * Parses out the header value from the HTTP header string.
 * @return the header value for the specified full header string, or<tt>null</tt> if the value could not be extracted
 */
public static String extractHeaderValue(final String header){
  int index=header.indexOf("String_Node_Str");
  if (index == 0)   return null;
  return header.substring(index + 1);
}

Fixed version (ground truth):
/** 
 * Parses out the header value from the HTTP header string.
 * @return the header value for the specified full header string, or<tt>null</tt> if the value could not be extracted
 */
public static String extractHeaderValue(final String header){
  int index=header.indexOf("String_Node_Str");
  if (index == 0)   return null;
  return header.substring(index + 2).trim();
}
Program: 4899
Project: 4899
Buggy source:
/** 
 * Returns the union of all XML metadata documents from all hosts.
 */
private synchronized LimeXMLDocument[] getXMLDocuments(){
}

Fixed version (ground truth):
/** 
 * Returns the union of all XML metadata documents from all hosts.
 */
private synchronized LimeXMLDocument[] getXMLDocuments(){
  LimeXMLDocument[] retArray=null;
  List allDocs=new ArrayList();
  for (int i=0; i < this.allFiles.length; i++) {
    if (this.allFiles[i] != null) {
      LimeXMLDocument doc=this.allFiles[i].getXMLDoc();
      if (doc != null) {
        allDocs.add(doc);
      }
    }
  }
  if (allDocs.size() > 0) {
    retArray=(LimeXMLDocument[])allDocs.toArray(new LimeXMLDocument[0]);
  }
 else   retArray=null;
  return retArray;
}
Program: 4900
Project: 4900
Buggy source:
/** 
 * Returns an array of all responses matching the given request, or null if there are no responses.<p> Design note: this method returns null instead of an empty array to avoid allocations in the common case of no matches.)
 */
public synchronized Response[] query(QueryRequest request){
  String str=request.getQuery();
  if (str.equals(INDEXING_QUERY) || str.equals(BROWSE_QUERY)) {
    if (_numFiles == 0)     return null;
    Response[] ret=new Response[_numFiles];
    int j=0;
    for (int i=0; i < _files.size(); i++) {
      FileDesc desc=(FileDesc)_files.get(i);
      if (desc == null)       continue;
      Assert.that(j < ret.length,"String_Node_Str");
      ret[j]=new Response(desc);
      j++;
    }
    Assert.that(j == ret.length,"String_Node_Str");
    return ret;
  }
  IntSet matches=null;
  matches=search(str,matches);
  if (request.getQueryUrns() != null) {
    matches=urnSearch(request.getQueryUrns().iterator(),matches);
  }
  if (matches == null)   return null;
  Response[] response=new Response[matches.size()];
  int j=0;
  for (IntSet.IntSetIterator iter=matches.iterator(); iter.hasNext(); j++) {
    int i=iter.next();
    FileDesc desc=(FileDesc)_files.get(i);
    response[j]=new Response(desc);
  }
  return response;
}

Fixed version (ground truth):
/** 
 * Returns an array of all responses matching the given request, or null if there are no responses.<p> Design note: this method returns null instead of an empty array to avoid allocations in the common case of no matches.)
 */
public synchronized Response[] query(QueryRequest request){
  String str=request.getQuery();
  if (str.equals(INDEXING_QUERY) || str.equals(BROWSE_QUERY)) {
    if (_numFiles == 0)     return null;
    Response[] ret=new Response[_numFiles];
    int j=0;
    for (int i=0; i < _files.size(); i++) {
      FileDesc desc=(FileDesc)_files.get(i);
      if (desc == null)       continue;
      Assert.that(j < ret.length,"String_Node_Str");
      ret[j]=new Response(desc);
      j++;
    }
    Assert.that(j == ret.length,"String_Node_Str");
    return ret;
  }
  IntSet matches=null;
  matches=search(str,matches);
  if (request.getQueryUrns().size() > 0) {
    matches=urnSearch(request.getQueryUrns().iterator(),matches);
  }
  if (matches == null) {
    return null;
  }
  Response[] response=new Response[matches.size()];
  int j=0;
  for (IntSet.IntSetIterator iter=matches.iterator(); iter.hasNext(); j++) {
    int i=iter.next();
    FileDesc desc=(FileDesc)_files.get(i);
    response[j]=new Response(desc);
  }
  return response;
}
Program: 4901
Project: 4901
Buggy source:
/** 
 * Indicates that the node is in the client node, and has now lost its only connection to the supernode
 */
private synchronized void lostShieldedClientSupernodeConnection(){
  if (_keepAlive > 0 && !hasClientSupernodeConnection()) {
    connect();
  }
}

Fixed version (ground truth):
/** 
 * Indicates that the node is in client mode and has lost a leaf to ultrapeer connection.
 */
private synchronized void lostShieldedClientSupernodeConnection(){
}
Program: 4902
Project: 4902
Buggy source:
/** 
 * Initializes a ManagedDownloader read from disk. Also used for internally initializing or resuming a normal download; there is no need to explicitly call this method in that case. After the call, this is in the queued state, at least for the moment.
 * @requires this is uninitialized or stopped, and allFiles, and incompleteFileManager are set
 * @modifies everything but the above fields 
 */
public void initialize(DownloadManager manager,FileManager fileManager){
  this.manager=manager;
  this.fileManager=fileManager;
  dloaders=new LinkedList();
  chatList=new DownloadChatList();
  stopped=false;
  corrupted=false;
  setState(QUEUED);
  this.dloaderManagerThread=new Thread(){
    public void run(){
      try {
        tryAllDownloads();
      }
 catch (      Exception e) {
        ManagedDownloader.this.manager.internalError(e);
      }
    }
  }
;
  dloaderManagerThread.setDaemon(true);
  dloaderManagerThread.start();
}

Fixed version (ground truth):
/** 
 * Initializes a ManagedDownloader read from disk. Also used for internally initializing or resuming a normal download; there is no need to explicitly call this method in that case. After the call, this is in the queued state, at least for the moment.
 * @requires this is uninitialized or stopped, and allFiles, and incompleteFileManager are set
 * @modifies everything but the above fields 
 */
public void initialize(DownloadManager manager,FileManager fileManager){
  this.manager=manager;
  this.fileManager=fileManager;
  dloaders=new LinkedList();
  chatList=new DownloadChatList();
  stopped=false;
  corrupted=false;
  setState(QUEUED);
  miniRFDToLock=Collections.synchronizedMap(new HashMap());
  threadLockToSocket=Collections.synchronizedMap(new HashMap());
  this.dloaderManagerThread=new Thread(){
    public void run(){
      try {
        tryAllDownloads();
      }
 catch (      Exception e) {
        ManagedDownloader.this.manager.internalError(e);
      }
    }
  }
;
  dloaderManagerThread.setDaemon(true);
  dloaderManagerThread.start();
}
Program: 4903
Project: 4903
Buggy source:
/** 
 * Initializes a ManagedDownloader read from disk. Also used for internally initializing or resuming a normal download; there is no need to explicitly call this method in that case. After the call, this is in the queued state, at least for the moment.
 * @requires this is uninitialized or stopped, and allFiles, and incompleteFileManager are set
 * @modifies everything but the above fields 
 */
public void initialize(DownloadManager manager,FileManager fileManager){
  this.manager=manager;
  this.fileManager=fileManager;
  dloaders=new LinkedList();
  chatList=new DownloadChatList();
  stopped=false;
  corrupted=false;
  setState(QUEUED);
  miniRFDToLock=Collections.synchronizedMap(new HashMap());
  threadLockToSocket=Collections.synchronizedMap(new HashMap());
  this.dloaderManagerThread=new Thread(){
    public void run(){
      try {
        tryAllDownloads();
      }
 catch (      Exception e) {
        ManagedDownloader.this.manager.internalError(e);
      }
    }
  }
;
  dloaderManagerThread.setDaemon(true);
  dloaderManagerThread.start();
}

Fixed version (ground truth):
/** 
 * Initializes a ManagedDownloader read from disk. Also used for internally initializing or resuming a normal download; there is no need to explicitly call this method in that case. After the call, this is in the queued state, at least for the moment.
 * @requires this is uninitialized or stopped, and allFiles, and incompleteFileManager are set
 * @modifies everything but the above fields 
 */
public void initialize(DownloadManager manager,FileManager fileManager){
  this.manager=manager;
  this.fileManager=fileManager;
  dloaders=new LinkedList();
  chatList=new DownloadChatList();
  stealLock=new Object();
  stopped=false;
  corrupted=false;
  setState(QUEUED);
  miniRFDToLock=Collections.synchronizedMap(new HashMap());
  threadLockToSocket=Collections.synchronizedMap(new HashMap());
  this.dloaderManagerThread=new Thread(){
    public void run(){
      try {
        tryAllDownloads();
      }
 catch (      Exception e) {
        ManagedDownloader.this.manager.internalError(e);
      }
    }
  }
;
  dloaderManagerThread.setDaemon(true);
  dloaderManagerThread.start();
}
Program: 4904
Project: 4904
Buggy source:
/** 
 * Returns true if this can safely switch from supernode to leaf mode. Typically that means there are no leaf connections, but it could be stricter.  
 */
public boolean allowClientMode(){
  if (_settings.getForceSupernodeMode() || (isSupernode() && _incomingClientConnections > 0))   return false;
 else   return true;
}

Fixed version (ground truth):
/** 
 * Returns true if this can safely switch from supernode to leaf mode. Typically that means there are no leaf connections, but it could be stricter.  
 */
public boolean allowClientMode(){
  int connections=getNumInitializedConnections() + _initializedClientConnections.size();
  if (_settings.getForceSupernodeMode() || (isSupernode() && connections > 0))   return false;
 else   return true;
}
Program: 4905
Project: 4905
Buggy source:
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str" + "String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setDirectories(new File[0]);
  settings.setUseQuickConnect(false);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  settings.setKeepAlive(KEEP_ALIVE);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  TestMessageRouter router=new TestMessageRouter(callback,files);
  RouterService rs=new RouterService(callback,router,files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    e.printStackTrace();
    Assert.that(false);
  }
  testFetchI(rs,router);
  cleanup(rs);
  testFetchII(rs,router);
  cleanup(rs);
  testAcceptI(rs,router,host,port);
  cleanup(rs);
  testAcceptII(rs,router,host,port);
  cleanup(rs);
  testAcceptIII(rs,router,host,port);
}

Fixed version (ground truth):
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str" + "String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setDirectories(new File[0]);
  settings.setUseQuickConnect(false);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setForceSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  settings.setKeepAlive(KEEP_ALIVE);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  TestMessageRouter router=new TestMessageRouter(callback,files);
  RouterService rs=new RouterService(callback,router,files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    e.printStackTrace();
    Assert.that(false);
  }
  System.out.println("String_Node_Str");
  testGuidanceI(rs);
  cleanup(rs);
  testGuidanceII(rs);
  cleanup(rs);
  testGuidanceIII(rs);
  cleanup(rs);
  testFetchI(rs,router);
  cleanup(rs);
  testFetchII(rs,router);
  cleanup(rs);
  testAcceptI(rs,router,host,port);
  cleanup(rs);
  testAcceptII(rs,router,host,port);
  cleanup(rs);
  testAcceptIII(rs,router,host,port);
}
Program: 4906
Project: 4906
Buggy source:
/** 
 * @return an XML string that will be re-created as this document when it is re-assembled in another machine. this xml string contains the filename identifier too (as an attribute).
 * @exception SchemaNotFoundException DO NOT CALL THIS METHOD unlessyou know that getSchemaURI() returns a valid xml schema.  Set it  yourself with setSchemaURI().
 */
public String getXMLStringWithIdentifier() throws SchemaNotFoundException {
  String ret=constructXML(getOrderedNameValueList(),schemaUri);
  int index=ret.indexOf("String_Node_Str");
  if (index < 0)   return ret;
  index=ret.indexOf("String_Node_Str",++index);
  index=ret.indexOf("String_Node_Str",++index);
  String first=ret.substring(0,index);
  String last=ret.substring(index);
  String middle="String_Node_Str" + identifier + "String_Node_Str";
  ret=first + middle + last;
  return ret;
}

Fixed version (ground truth):
/** 
 * @return an XML string that will be re-created as this document when it is re-assembled in another machine. this xml string contains the filename identifier too (as an attribute).
 * @exception SchemaNotFoundException DO NOT CALL THIS METHOD unlessyou know that getSchemaURI() returns a valid xml schema.  Set it  yourself with setSchemaURI().
 */
public String getXMLStringWithIdentifier() throws SchemaNotFoundException {
  String ret=getXMLString();
  int index=ret.indexOf("String_Node_Str");
  if (index < 0)   return ret;
  index=ret.indexOf("String_Node_Str",++index);
  index=ret.indexOf("String_Node_Str",++index);
  String first=ret.substring(0,index);
  String last=ret.substring(index);
  String middle="String_Node_Str" + identifier + "String_Node_Str";
  ret=first + middle + last;
  return ret;
}
Program: 4909
Project: 4909
Buggy source:
/** 
 * @return an XML string that will be re-created as this document when it is re-assembled in another machine. 
 * @exception SchemaNotFoundException DO NOT CALL THIS METHOD unlessyou know that getSchemaURI() returns a valid xml schema.  Set it  yourself with setSchemaURI().
 */
public String getXMLString() throws SchemaNotFoundException {
  String ret=constructXML(getOrderedNameValueList(),schemaUri);
  return ret;
}

Fixed version (ground truth):
/** 
 * @return an XML string that will be re-created as this document when it is re-assembled in another machine. 
 * @exception SchemaNotFoundException DO NOT CALL THIS METHOD unlessyou know that getSchemaURI() returns a valid xml schema.  Set it  yourself with setSchemaURI().
 */
public String getXMLString() throws SchemaNotFoundException {
  if (xmlString == null) {
    xmlString=constructXML(getOrderedNameValueList(),schemaUri);
  }
  return xmlString;
}
Program: 4911
Project: 4911
Buggy source:
/** 
 * Returns the address of the foreign host this is connected to.
 * @requires this is initialized.
 */
public InetAddress getInetAddress(){
  return _socket.getInetAddress();
}

Fixed version (ground truth):
/** 
 * Returns the address of the foreign host this is connected to.
 * @exception IllegalStateException this is not initialized
 */
public InetAddress getInetAddress() throws IllegalStateException {
  try {
    return _socket.getInetAddress();
  }
 catch (  NullPointerException e) {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 4912
Project: 4912
Buggy source:
/** 
 * Returns the port this is connected to locally.
 * @requires this is initialized.
 */
public int getLocalPort(){
  return _socket.getLocalPort();
}

Fixed version (ground truth):
/** 
 * Returns the port this is connected to locally.
 * @exception IllegalStateException this is not initialized
 */
public int getLocalPort() throws IllegalStateException {
  try {
    return _socket.getLocalPort();
  }
 catch (  NullPointerException e) {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 4913
Project: 4913
Buggy source:
/** 
 * Returns the local address of this.
 * @requires this is initialized.
 */
public InetAddress getLocalAddress(){
  return _socket.getLocalAddress();
}

Fixed version (ground truth):
/** 
 * Returns the local address of this.
 * @exception IllegalStateException this is not initialized
 */
public InetAddress getLocalAddress() throws IllegalStateException {
  try {
    return _socket.getLocalAddress();
  }
 catch (  NullPointerException e) {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 4914
Project: 4914
Buggy source:
/** 
 * Returns the port of the foreign host this is connected to.
 * @requires this is initialized.
 */
public int getPort(){
  return _socket.getPort();
}

Fixed version (ground truth):
/** 
 * Returns the port of the foreign host this is connected to.
 * @exception IllegalStateException this is not initialized
 */
public int getPort() throws IllegalStateException {
  try {
    return _socket.getPort();
  }
 catch (  NullPointerException e) {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 4915
Project: 4915
Buggy source:
/** 
 * An unsynchronized version of remove, meant to be used when the monitor is already held.  This version does not kick off ConnectionFetchers; only the externally exposed version of remove does that.
 */
private void removeInternal(ManagedConnection c){
  boolean removed=false;
  if (!c.isSupernodeClientConnection()) {
    int i=_initializedConnections.indexOf(c);
    if (i != -1) {
      removed=true;
      List newConnections=new ArrayList();
      newConnections.addAll(_initializedConnections);
      newConnections.remove(c);
      _initializedConnections=newConnections;
    }
  }
 else {
    int i=_initializedClientConnections.indexOf(c);
    if (i != -1) {
      removed=true;
      List newConnections=new ArrayList();
      newConnections.addAll(_initializedClientConnections);
      newConnections.remove(c);
      _initializedClientConnections=newConnections;
    }
  }
  if (removed) {
    Set newEndpoints=new HashSet();
    newEndpoints.addAll(_endpoints);
    newEndpoints.remove(new Endpoint(c.getInetAddress().getHostAddress(),c.getPort()));
    _endpoints=newEndpoints;
  }
  int i=_connections.indexOf(c);
  if (i != -1) {
    List newConnections=new ArrayList(_connections);
    newConnections.remove(c);
    _connections=newConnections;
  }
  c.close();
  _router.removeConnection(c);
  _callback.connectionClosed(c);
}

Fixed version (ground truth):
/** 
 * An unsynchronized version of remove, meant to be used when the monitor is already held.  This version does not kick off ConnectionFetchers; only the externally exposed version of remove does that.
 */
private void removeInternal(ManagedConnection c){
  boolean removed=false;
  if (!c.isSupernodeClientConnection()) {
    int i=_initializedConnections.indexOf(c);
    if (i != -1) {
      removed=true;
      List newConnections=new ArrayList();
      newConnections.addAll(_initializedConnections);
      newConnections.remove(c);
      _initializedConnections=newConnections;
    }
  }
 else {
    int i=_initializedClientConnections.indexOf(c);
    if (i != -1) {
      removed=true;
      List newConnections=new ArrayList();
      newConnections.addAll(_initializedClientConnections);
      newConnections.remove(c);
      _initializedClientConnections=newConnections;
    }
  }
  int i=_connections.indexOf(c);
  if (i != -1) {
    List newConnections=new ArrayList(_connections);
    newConnections.remove(c);
    _connections=newConnections;
  }
  c.close();
  _router.removeConnection(c);
  _callback.connectionClosed(c);
}
Program: 4916
Project: 4916
Buggy source:
/** 
 * Marks a connection fully initialized, but only if that connection wasn't removed from the list of open connections during its initialization. Should only be called from a thread that has this' monitor.
 */
private void connectionInitialized(ManagedConnection c){
  if (_connections.contains(c)) {
    if (!c.isSupernodeClientConnection()) {
      List newConnections=new ArrayList(_initializedConnections);
      newConnections.add(c);
      _initializedConnections=newConnections;
    }
 else {
      List newConnections=new ArrayList(_initializedClientConnections);
      newConnections.add(c);
      _initializedClientConnections=newConnections;
    }
    Set newEndpoints=new HashSet(_endpoints);
    newEndpoints.add(new Endpoint(c.getInetAddress().getHostAddress(),c.getPort()));
    _endpoints=newEndpoints;
  }
}

Fixed version (ground truth):
/** 
 * Marks a connection fully initialized, but only if that connection wasn't removed from the list of open connections during its initialization. Should only be called from a thread that has this' monitor.
 */
private void connectionInitialized(ManagedConnection c){
  if (_connections.contains(c)) {
    if (!c.isSupernodeClientConnection()) {
      List newConnections=new ArrayList(_initializedConnections);
      newConnections.add(c);
      _initializedConnections=newConnections;
    }
 else {
      List newConnections=new ArrayList(_initializedClientConnections);
      newConnections.add(c);
      _initializedClientConnections=newConnections;
    }
  }
}