nus-yam/ex-repair huggingface dataset:
Program: 100757
Project: 100757
Buggy source:
/** 
 * Process attributes
 * @param qName element name
 * @param atts input attributes
 * @param res attributes to write to
 * @throws IOException if writing to output failed
 */
private void processAttributes(final String qName,final Attributes atts,final AttributesImpl res) throws IOException {
  final int attsLen=atts.getLength();
  for (int i=0; i < attsLen; i++) {
    final String attQName=atts.getQName(i);
    String attValue=getAttributeValue(qName,attQName,atts.getValue(i));
    if (ATTRIBUTE_NAME_CONREF.equals(attQName)) {
      XMLUtils.addOrSetAttribute(res,ATTRIBUTE_NAME_CONREF,replaceCONREF(atts).toString());
    }
 else     if (ATTRIBUTE_NAME_HREF.equals(attQName) || ATTRIBUTE_NAME_COPY_TO.equals(attQName)) {
      if (atts.getValue(ATTRIBUTE_NAME_SCOPE) == null || atts.getValue(ATTRIBUTE_NAME_SCOPE).equals(ATTR_SCOPE_VALUE_LOCAL)) {
        attValue=replaceHREF(attQName,atts).toString();
      }
      XMLUtils.addOrSetAttribute(res,attQName,attValue);
    }
 else {
      XMLUtils.addOrSetAttribute(res,atts.getURI(i),atts.getLocalName(i),attQName,atts.getType(i),attValue);
    }
  }
}

Fixed version (ground truth):
/** 
 * Process attributes
 * @param qName element name
 * @param atts input attributes
 * @param res attributes to write to
 * @throws IOException if writing to output failed
 */
private void processAttributes(final String qName,final Attributes atts,final AttributesImpl res){
  final int attsLen=atts.getLength();
  for (int i=0; i < attsLen; i++) {
    final String attQName=atts.getQName(i);
    String attValue=getAttributeValue(qName,attQName,atts.getValue(i));
    if (ATTRIBUTE_NAME_CONREF.equals(attQName)) {
      XMLUtils.addOrSetAttribute(res,ATTRIBUTE_NAME_CONREF,replaceCONREF(atts).toString());
    }
 else     if (ATTRIBUTE_NAME_HREF.equals(attQName) || ATTRIBUTE_NAME_COPY_TO.equals(attQName)) {
      if (atts.getValue(ATTRIBUTE_NAME_SCOPE) == null || atts.getValue(ATTRIBUTE_NAME_SCOPE).equals(ATTR_SCOPE_VALUE_LOCAL)) {
        attValue=replaceHREF(attQName,atts).toString();
      }
      XMLUtils.addOrSetAttribute(res,attQName,attValue);
    }
 else {
      XMLUtils.addOrSetAttribute(res,atts.getURI(i),atts.getLocalName(i),attQName,atts.getType(i),attValue);
    }
  }
}
Program: 100758
Project: 100758
Buggy source:
private List<IndexTerm> cloneIndextermList(final List<IndexTerm> termList){
  final List<IndexTerm> termListClone=new ArrayList<IndexTerm>(termList.size());
  if (termList != null && !termList.isEmpty()) {
    for (int i=0; i < termList.size(); i++) {
      termListClone.add(termList.get(i));
    }
  }
  return termListClone;
}

Fixed version (ground truth):
private List<IndexTerm> cloneIndextermList(final List<IndexTerm> termList){
  final List<IndexTerm> termListClone=new ArrayList<IndexTerm>(termList.size());
  if (termList != null && !termList.isEmpty()) {
    for (    IndexTerm aTermList : termList) {
      termListClone.add(aTermList);
    }
  }
  return termListClone;
}
Program: 100760
Project: 100760
Buggy source:
private void outputIndexEntryEclipseIndexsee(final IndexTerm term,final XMLStreamWriter serializer) throws XMLStreamException {
  final List<IndexTermTarget> targets=term.getTargetList();
  final int targetNum=targets.size();
  if (targets != null && !targets.isEmpty()) {
    for (int i=0; i < targetNum; i++) {
      final IndexTermTarget target=targets.get(i);
      final String targetUri=target.getTargetURI();
      final String targetName=target.getTargetName();
      if (targetUri == null) {
        serializer.writeStartElement("String_Node_Str");
        serializer.writeAttribute("String_Node_Str",target.getTargetName());
        serializer.writeEndElement();
      }
 else {
        serializer.writeStartElement("String_Node_Str");
        serializer.writeAttribute("String_Node_Str",replaceExtName(targetUri));
        if (targetName.trim().length() > 0) {
          serializer.writeAttribute("String_Node_Str",target.getTargetName());
        }
        serializer.writeEndElement();
      }
    }
  }
}

Fixed version (ground truth):
private void outputIndexEntryEclipseIndexsee(final IndexTerm term,final XMLStreamWriter serializer) throws XMLStreamException {
  final List<IndexTermTarget> targets=term.getTargetList();
  final int targetNum=targets.size();
  if (targets != null && !targets.isEmpty()) {
    for (    final IndexTermTarget target : targets) {
      final String targetUri=target.getTargetURI();
      final String targetName=target.getTargetName();
      if (targetUri == null) {
        serializer.writeStartElement("String_Node_Str");
        serializer.writeAttribute("String_Node_Str",target.getTargetName());
        serializer.writeEndElement();
      }
 else {
        serializer.writeStartElement("String_Node_Str");
        serializer.writeAttribute("String_Node_Str",replaceExtName(targetUri));
        if (targetName.trim().length() > 0) {
          serializer.writeAttribute("String_Node_Str",target.getTargetName());
        }
        serializer.writeEndElement();
      }
    }
  }
}
Program: 100761
Project: 100761
Buggy source:
@Override public void processingInstruction(final String target,final String data) throws SAXException {
  String d=data;
  if (target.equals(PI_WORKDIR_TARGET)) {
    if (workdir != null) {
      try {
        if (OS_NAME.toLowerCase().indexOf(OS_NAME_WINDOWS) == -1) {
          d=workdir.getCanonicalPath();
        }
 else {
          d=UNIX_SEPARATOR + workdir.getCanonicalPath();
        }
      }
 catch (      final IOException e) {
        throw new RuntimeException("String_Node_Str" + e.getMessage(),e);
      }
    }
  }
 else   if (target.equals(PI_WORKDIR_TARGET_URI)) {
    if (workdir != null) {
      d=workdir.toURI().toString();
    }
  }
 else   if (target.equals(PI_PATH2PROJ_TARGET)) {
    if (path2project != null) {
      d=path2project;
    }
  }
 else   if (target.equals(PI_PATH2PROJ_TARGET_URI)) {
    if (path2project != null) {
      d=URLUtils.correct(path2project,true);
    }
  }
  getContentHandler().processingInstruction(target,d);
}

Fixed version (ground truth):
@Override public void processingInstruction(final String target,final String data) throws SAXException {
  String d=data;
  if (target.equals(PI_WORKDIR_TARGET)) {
    if (workdir != null) {
      try {
        if (OS_NAME.toLowerCase().indexOf(OS_NAME_WINDOWS) == -1) {
          d=workdir.getCanonicalPath();
        }
 else {
          d=UNIX_SEPARATOR + workdir.getCanonicalPath();
        }
      }
 catch (      final IOException e) {
        throw new RuntimeException("String_Node_Str" + e.getMessage(),e);
      }
    }
  }
 else   if (target.equals(PI_WORKDIR_TARGET_URI)) {
    if (workdir != null) {
      d=workdir.toURI().toString();
    }
  }
 else   if (target.equals(PI_PATH2PROJ_TARGET)) {
    if (path2project != null) {
      d=path2project;
    }
  }
 else   if (target.equals(PI_PATH2PROJ_TARGET_URI)) {
    if (path2project != null) {
      d=URLUtils.correct(FileUtils.separatorsToUnix(path2project),true);
    }
  }
  getContentHandler().processingInstruction(target,d);
}
Program: 100762
Project: 100762
Buggy source:
/** 
 * Get job configuration from Ant project reference or create new.
 * @param tempDir configuration directory 
 * @param project Ant project
 * @return job configuration
 */
public static Job getJob(final File tempDir,final Project project){
  Job job=project.getReference(ANT_REFERENCE_JOB);
  if (job != null && job.isStale(tempDir)) {
    project.log("String_Node_Str",Project.MSG_VERBOSE);
    job=null;
  }
  if (job == null) {
    try {
      job=new Job(tempDir);
    }
 catch (    final IOException ioe) {
      throw new BuildException(ioe);
    }
    project.addReference(ANT_REFERENCE_JOB,job);
  }
  return job;
}

Fixed version (ground truth):
/** 
 * Get job configuration from Ant project reference or create new.
 * @param tempDir configuration directory 
 * @param project Ant project
 * @return job configuration
 */
public static Job getJob(final File tempDir,final Project project){
  Job job=(Job)project.getReference(ANT_REFERENCE_JOB);
  if (job != null && job.isStale(tempDir)) {
    project.log("String_Node_Str",Project.MSG_VERBOSE);
    job=null;
  }
  if (job == null) {
    try {
      job=new Job(tempDir);
    }
 catch (    final IOException ioe) {
      throw new BuildException(ioe);
    }
    project.addReference(ANT_REFERENCE_JOB,job);
  }
  return job;
}
Program: 100764
Project: 100764
Buggy source:
/** 
 * Parse filter file. From GenMapAndTopicListModule.
 * @return configured filter utility
 */
private FilterUtils parseFilterFile(final String ditavalFile){
  final FilterUtils filterUtils=new FilterUtils();
  filterUtils.setLogger(logger);
  if (ditavalFile != null) {
    final DitaValReader ditaValReader=new DitaValReader();
    ditaValReader.setLogger(logger);
    ditaValReader.initXMLReader(true);
    ditaValReader.read(new File(ditavalFile).getAbsoluteFile());
    filterUtils.setFilterMap(ditaValReader.getFilterMap());
  }
 else {
    filterUtils.setFilterMap(null);
  }
  return filterUtils;
}

Fixed version (ground truth):
/** 
 * Parse filter file. From GenMapAndTopicListModule.
 * @return configured filter utility
 */
private FilterUtils parseFilterFile(final String ditavalFile){
  final FilterUtils filterUtils=new FilterUtils();
  filterUtils.setLogger(logger);
  if (ditavalFile != null) {
    final DitaValReader ditaValReader=new DitaValReader();
    ditaValReader.setLogger(logger);
    ditaValReader.initXMLReader(true);
    ditaValReader.read(new File(ditavalFile).getAbsoluteFile());
    filterUtils.setFilterMap(ditaValReader.getFilterMap());
  }
 else {
    filterUtils.setFilterMap(Collections.EMPTY_MAP);
  }
  return filterUtils;
}
Program: 100765
Project: 100765
Buggy source:
/** 
 * Handle copy-to topics.
 */
private void handleCopyto(){
  final Map<File,File> tempMap=new HashMap<File,File>();
  for (  final File dst : copytoMap.keySet()) {
    final File src=copytoMap.get(dst);
    if (job.getFileInfoMap().containsKey(dst)) {
      tempMap.put(dst,src);
      final FileInfo orig=job.getFileInfoMap().get(src);
      final FileInfo.Builder b=new FileInfo.Builder(orig);
      b.uri(toURI(dst));
      final FileInfo f=b.build();
      job.add(f);
    }
  }
  copytoMap=tempMap;
  ditaSet.addAll(copytoMap.keySet());
  fullTopicSet.addAll(copytoMap.keySet());
  final Set<File> totalCopytoSources=new HashSet<File>(128);
  totalCopytoSources.addAll(copytoMap.values());
  totalCopytoSources.addAll(ignoredCopytoSourceSet);
  final Set<File> pureCopytoSources=new HashSet<File>(128);
  for (  final File src : totalCopytoSources) {
    if (!nonConrefCopytoTargetSet.contains(src) && !copytoMap.keySet().contains(src)) {
      pureCopytoSources.add(src);
    }
  }
  copytoSourceSet=pureCopytoSources;
  ditaSet.removeAll(pureCopytoSources);
  fullTopicSet.removeAll(pureCopytoSources);
}

Fixed version (ground truth):
/** 
 * Handle copy-to topics.
 */
private void handleCopyto(){
  final Map<File,File> tempMap=new HashMap<File,File>();
  for (  final File dst : copytoMap.keySet()) {
    final File src=copytoMap.get(dst);
    if (job.getFileInfoMap().containsKey(dst.getPath())) {
      tempMap.put(dst,src);
      final FileInfo orig=job.getFileInfoMap().get(src.getPath());
      final FileInfo.Builder b=new FileInfo.Builder(orig);
      b.uri(toURI(dst));
      final FileInfo f=b.build();
      job.add(f);
    }
  }
  copytoMap=tempMap;
  ditaSet.addAll(copytoMap.keySet());
  fullTopicSet.addAll(copytoMap.keySet());
  final Set<File> totalCopytoSources=new HashSet<File>(128);
  totalCopytoSources.addAll(copytoMap.values());
  totalCopytoSources.addAll(ignoredCopytoSourceSet);
  final Set<File> pureCopytoSources=new HashSet<File>(128);
  for (  final File src : totalCopytoSources) {
    if (!nonConrefCopytoTargetSet.contains(src) && !copytoMap.keySet().contains(src)) {
      pureCopytoSources.add(src);
    }
  }
  copytoSourceSet=pureCopytoSources;
  ditaSet.removeAll(pureCopytoSources);
  fullTopicSet.removeAll(pureCopytoSources);
}
Program: 100766
Project: 100766
Buggy source:
/** 
 * Categorize file. If   {@code file} parameter contains a pipe character, the pipe character is followedby the format of the file. TODO: Pass format as separate DITA class parameter.
 * @param file file system path with optional format
 */
private void categorizeResultFile(final Reference file){
  final String lcasefn=file.filename.toLowerCase();
  if (subsidiarySet.contains(lcasefn)) {
    return;
  }
  if (FileUtils.isDITAFile(lcasefn) && (file.format == null || ATTR_FORMAT_VALUE_DITA.equalsIgnoreCase(file.format) || ATTR_FORMAT_VALUE_DITAMAP.equalsIgnoreCase(file.format))) {
    addToWaitList(new File(file.filename));
  }
 else   if (!FileUtils.isSupportedImageFile(lcasefn)) {
    htmlSet.add(new File(file.filename));
  }
  if (FileUtils.isSupportedImageFile(lcasefn)) {
    imageSet.add(new File(file.filename));
    try {
      final File image=new File(baseInputDir,file.filename).getCanonicalFile();
      if (!image.exists()) {
        logger.logWarn(MessageUtils.getInstance().getMessage("String_Node_Str",image.getAbsolutePath()).toString());
      }
    }
 catch (    final IOException e) {
      logger.logError(e.getMessage());
    }
  }
  if (FileUtils.isHTMLFile(lcasefn) || FileUtils.isResourceFile(lcasefn)) {
    htmlSet.add(new File(file.filename));
  }
}

Fixed version (ground truth):
/** 
 * Categorize file. If   {@code file} parameter contains a pipe character, the pipe character is followedby the format of the file. TODO: Pass format as separate DITA class parameter.
 * @param file file system path with optional format
 */
private void categorizeResultFile(final Reference file){
  final String lcasefn=file.filename.toLowerCase();
  if (subsidiarySet.contains(toFile(file.filename))) {
    return;
  }
  if (FileUtils.isDITAFile(lcasefn) && (file.format == null || ATTR_FORMAT_VALUE_DITA.equalsIgnoreCase(file.format) || ATTR_FORMAT_VALUE_DITAMAP.equalsIgnoreCase(file.format))) {
    addToWaitList(new File(file.filename));
  }
 else   if (!FileUtils.isSupportedImageFile(lcasefn)) {
    htmlSet.add(new File(file.filename));
  }
  if (FileUtils.isSupportedImageFile(lcasefn)) {
    imageSet.add(new File(file.filename));
    try {
      final File image=new File(baseInputDir,file.filename).getCanonicalFile();
      if (!image.exists()) {
        logger.logWarn(MessageUtils.getInstance().getMessage("String_Node_Str",image.getAbsolutePath()).toString());
      }
    }
 catch (    final IOException e) {
      logger.logError(e.getMessage());
    }
  }
  if (FileUtils.isHTMLFile(lcasefn) || FileUtils.isResourceFile(lcasefn)) {
    htmlSet.add(new File(file.filename));
  }
}
Program: 100767
Project: 100767
Buggy source:
private void updateReltable(final Element elem){
  final String hrefValue=elem.getAttribute(ATTRIBUTE_NAME_HREF);
  if (hrefValue.length() != 0) {
    if (changeTable.containsKey(resolveFile(filePath,hrefValue))) {
      String resulthrefValue=null;
      final String fragment=getFragment(hrefValue);
      if (fragment != null) {
        resulthrefValue=getRelativeUnixPath(filePath + UNIX_SEPARATOR + FILE_NAME_STUB_DITAMAP,resolveFile(filePath,hrefValue).getPath()) + fragment;
      }
 else {
        resulthrefValue=getRelativeUnixPath(filePath + UNIX_SEPARATOR + FILE_NAME_STUB_DITAMAP,resolveFile(filePath,hrefValue).getPath());
      }
      elem.setAttribute(ATTRIBUTE_NAME_HREF,resulthrefValue);
    }
  }
  final NodeList children=elem.getChildNodes();
  for (int i=0; i < children.getLength(); i++) {
    final Node current=children.item(i);
    if (current.getNodeType() == Node.ELEMENT_NODE) {
      final Element currentElem=(Element)current;
      final String classValue=currentElem.getAttribute(ATTRIBUTE_NAME_CLASS);
      if (MAP_TOPICREF.matches(classValue)) {
      }
    }
  }
}

Fixed version (ground truth):
private void updateReltable(final Element elem){
  final String hrefValue=elem.getAttribute(ATTRIBUTE_NAME_HREF);
  if (hrefValue.length() != 0) {
    if (changeTable.containsKey(resolveFile(filePath,hrefValue).getPath())) {
      String resulthrefValue=null;
      final String fragment=getFragment(hrefValue);
      if (fragment != null) {
        resulthrefValue=getRelativeUnixPath(filePath + UNIX_SEPARATOR + FILE_NAME_STUB_DITAMAP,resolveFile(filePath,hrefValue).getPath()) + fragment;
      }
 else {
        resulthrefValue=getRelativeUnixPath(filePath + UNIX_SEPARATOR + FILE_NAME_STUB_DITAMAP,resolveFile(filePath,hrefValue).getPath());
      }
      elem.setAttribute(ATTRIBUTE_NAME_HREF,resulthrefValue);
    }
  }
  final NodeList children=elem.getChildNodes();
  for (int i=0; i < children.getLength(); i++) {
    final Node current=children.item(i);
    if (current.getNodeType() == Node.ELEMENT_NODE) {
      final Element currentElem=(Element)current;
      final String classValue=currentElem.getAttribute(ATTRIBUTE_NAME_CLASS);
      if (MAP_TOPICREF.matches(classValue)) {
      }
    }
  }
}
Program: 100768
Project: 100768
Buggy source:
private void processChildTopicref(final Node node){
  final NodeList children=node.getChildNodes();
  for (int i=0; i < children.getLength(); i++) {
    final Node current=children.item(i);
    if (current.getNodeType() == Node.ELEMENT_NODE) {
      final Element currentElem=(Element)current;
      final String classValue=currentElem.getAttribute(ATTRIBUTE_NAME_CLASS);
      final String hrefValue=currentElem.getAttribute(ATTRIBUTE_NAME_HREF);
      final String xtrfValue=currentElem.getAttribute(ATTRIBUTE_NAME_XTRF);
      if (MAP_TOPICREF.matches(classValue)) {
        if ((hrefValue.length() != 0 && !ATTR_XTRF_VALUE_GENERATED.equals(xtrfValue) && !resolveFile(filePath,hrefValue).equals(changeTable.get(resolveFile(filePath,hrefValue)))) || MAPGROUP_D_TOPICHEAD.matches(classValue)) {
          processTopicref(currentElem);
        }
 else         if (hrefValue.length() == 0) {
          processTopicref(currentElem);
        }
      }
    }
  }
}

Fixed version (ground truth):
private void processChildTopicref(final Node node){
  final NodeList children=node.getChildNodes();
  for (int i=0; i < children.getLength(); i++) {
    final Node current=children.item(i);
    if (current.getNodeType() == Node.ELEMENT_NODE) {
      final Element currentElem=(Element)current;
      final String classValue=currentElem.getAttribute(ATTRIBUTE_NAME_CLASS);
      final String hrefValue=currentElem.getAttribute(ATTRIBUTE_NAME_HREF);
      final String xtrfValue=currentElem.getAttribute(ATTRIBUTE_NAME_XTRF);
      if (MAP_TOPICREF.matches(classValue)) {
        if ((hrefValue.length() != 0 && !ATTR_XTRF_VALUE_GENERATED.equals(xtrfValue) && !resolveFile(filePath,hrefValue).getPath().equals(changeTable.get(resolveFile(filePath,hrefValue).getPath()))) || MAPGROUP_D_TOPICHEAD.matches(classValue)) {
          processTopicref(currentElem);
        }
 else         if (hrefValue.length() == 0) {
          processTopicref(currentElem);
        }
      }
    }
  }
}
Program: 100771
Project: 100771
Buggy source:
private void addNamespace(final String uri,final String prefix,final QName current){
  if (uri.equals(NULL_NS_URI) && !prefix.equals(DEFAULT_NS_PREFIX)) {
    throw new IllegalArgumentException("String_Node_Str" + prefix + "String_Node_Str");
  }
  if (uri != null) {
    boolean found=false;
    stack:     for (    final QName e : elementStack) {
      for (      final NamespaceMapping m : e.mappings) {
        if (m.uri.equals(uri) && m.prefix.equals(prefix)) {
          found=true;
          break stack;
        }
 else         if (m.prefix.equals(prefix)) {
          break stack;
        }
      }
    }
    if (!found && uri.equals(NULL_NS_URI) && prefix.equals(DEFAULT_NS_PREFIX)) {
      return;
    }
    current.mappings.add(new NamespaceMapping(prefix,uri,!found));
  }
}

Fixed version (ground truth):
private void addNamespace(final String uri,final String prefix,final QName current){
  if (uri != null && uri.equals(NULL_NS_URI) && !prefix.equals(DEFAULT_NS_PREFIX)) {
    throw new IllegalArgumentException("String_Node_Str" + prefix + "String_Node_Str");
  }
  if (uri != null) {
    boolean found=false;
    stack:     for (    final QName e : elementStack) {
      for (      final NamespaceMapping m : e.mappings) {
        if (m.uri.equals(uri) && m.prefix.equals(prefix)) {
          found=true;
          break stack;
        }
 else         if (m.prefix.equals(prefix)) {
          break stack;
        }
      }
    }
    if (!found && uri.equals(NULL_NS_URI) && prefix.equals(DEFAULT_NS_PREFIX)) {
      return;
    }
    current.mappings.add(new NamespaceMapping(prefix,uri,!found));
  }
}
Program: 100774
Project: 100774
Buggy source:
/** 
 * Search braches map with branch id and current file name.
 * @param id String branch id.
 * @return boolean true if found and false otherwise.
 */
private boolean searchBrachesMap(final String id){
  if (validBranches.containsKey(currentFileRelative)) {
    final List<String> branchIdList=validBranches.get(currentFileRelative);
    if (branchIdList.contains(id)) {
      return true;
    }
 else     if (branchIdList.size() == 0) {
      return true;
    }
 else {
      return false;
    }
  }
 else {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Search braches map with branch id and current file name.
 * @param id String branch id.
 * @return boolean true if found and false otherwise.
 */
private boolean searchBrachesMap(final String id){
  if (validBranches.containsKey(currentFileRelative.getPath())) {
    final List<String> branchIdList=validBranches.get(currentFileRelative.getPath());
    if (branchIdList.contains(id)) {
      return true;
    }
 else     if (branchIdList.size() == 0) {
      return true;
    }
 else {
      return false;
    }
  }
 else {
    return false;
  }
}
Program: 100776
Project: 100776
Buggy source:
/** 
 * Set copy-to map.
 */
public void setCopytoMap(final Map<File,File> value){
  prop.put(COPYTO_TARGET_TO_SOURCE_MAP_LIST,new HashMap<File,File>(value));
}

Fixed version (ground truth):
/** 
 * Set copy-to map.
 */
public void setCopytoMap(final Map<File,File> value){
  final Map<String,String> res=new HashMap<String,String>();
  for (  final Map.Entry<File,File> e : value.entrySet()) {
    res.put(e.getKey().toString(),e.getValue().toString());
  }
  prop.put(COPYTO_TARGET_TO_SOURCE_MAP_LIST,res);
}
Program: 100779
Project: 100779
Buggy source:
/** 
 * Add set of values of job configuration
 * @param prop job configuration
 * @param key list name
 * @param set values to add
 */
private void addSetToProperties(final Job prop,final String key,final Set<String> set){
  final Set<String> newSet=new LinkedHashSet<String>(INT_128);
  for (  final String file : set) {
    if (new File(file).isAbsolute()) {
      newSet.add(FileUtils.normalize(file));
    }
 else {
      newSet.add(FileUtils.separatorsToUnix(FileUtils.normalize(prefix + file)));
    }
  }
  prop.setSet(key,newSet);
}

Fixed version (ground truth):
/** 
 * Add set of values of job configuration
 * @param prop job configuration
 * @param key list name
 * @param set values to add
 */
private void addSetToProperties(final Job prop,final String key,final Set<String> set){
  final Set<String> newSet=new LinkedHashSet<String>(INT_128);
  for (  final String file : set) {
    if (new File(file).isAbsolute()) {
      newSet.add(FileUtils.normalize(file));
    }
 else {
      newSet.add(FileUtils.normalize(prefix + file));
    }
  }
  prop.setSet(key,newSet);
}
Program: 100780
Project: 100780
Buggy source:
/** 
 * Normalize the input file path, by replacing all the '\\', '/' with File.seperator, and removing '..' from the directory. <p>Note: the substring behind "#" will be removed.</p>
 * @param basedir base dir
 * @param filepath file path
 * @return normalized path
 */
public static String normalizeDirectory(final String basedir,final String filepath){
  final String pathname=stripFragment(filepath);
  if (basedir == null || basedir.length() == 0) {
    return pathname;
  }
  final String normilizedPath=new File(basedir,pathname).getPath();
  return FileUtils.normalize(normilizedPath);
}

Fixed version (ground truth):
/** 
 * Normalize the input file path, by replacing all the '\\', '/' with File.seperator, and removing '..' from the directory. <p>Note: the substring behind "#" will be removed.</p> TODO: Return File
 * @param basedir base dir
 * @param filepath file path
 * @return normalized path
 */
public static String normalizeDirectory(final String basedir,final String filepath){
  final String pathname=FileUtils.normalize(stripFragment(filepath));
  if (basedir == null || basedir.length() == 0) {
    return pathname;
  }
  final String normilizedPath=new File(basedir,pathname).getPath();
  return FileUtils.normalize(normilizedPath);
}
Program: 100781
Project: 100781
Buggy source:
/** 
 * Remove redundant names ".." and "." from the given path.
 * @param path input path
 * @param separator directory separator
 * @return processed path
 */
public static String normalize(final String path,final String separator){
  final List<String> dirs=new LinkedList<String>();
  final StringTokenizer tokenizer=new StringTokenizer(path,separator);
  while (tokenizer.hasMoreTokens()) {
    final String token=tokenizer.nextToken();
    if (!("String_Node_Str".equals(token))) {
      dirs.add(token);
    }
  }
  int dirNum=dirs.size();
  int i=0;
  while (i < dirNum) {
    if (i > 0) {
      final String lastDir=dirs.get(i - 1);
      final String dir=dirs.get(i);
      if ("String_Node_Str".equals(dir) && !("String_Node_Str".equals(lastDir))) {
        dirs.remove(i);
        dirs.remove(i - 1);
        dirNum=dirs.size();
        i=i - 1;
        continue;
      }
    }
    i++;
  }
  final StringBuffer buff=new StringBuffer(path.length());
  if (path.startsWith(separator + separator)) {
    buff.append(separator).append(separator);
  }
 else   if (path.startsWith(separator)) {
    buff.append(separator);
  }
  final Iterator<String> iter=dirs.iterator();
  while (iter.hasNext()) {
    buff.append(iter.next());
    if (iter.hasNext()) {
      buff.append(separator);
    }
  }
  if (path.endsWith(separator)) {
    buff.append(separator);
  }
  return buff.toString();
}

Fixed version (ground truth):
/** 
 * Remove redundant names ".." and "." from the given path and replace directory separators.
 * @param path input path
 * @param separator directory separator
 * @return processed path
 */
public static String normalize(final String path,final String separator){
  final String p=path.replace(WINDOWS_SEPARATOR,separator).replace(UNIX_SEPARATOR,separator);
  final List<String> dirs=new LinkedList<String>();
  final StringTokenizer tokenizer=new StringTokenizer(p,separator);
  while (tokenizer.hasMoreTokens()) {
    final String token=tokenizer.nextToken();
    if (!("String_Node_Str".equals(token))) {
      dirs.add(token);
    }
  }
  int dirNum=dirs.size();
  int i=0;
  while (i < dirNum) {
    if (i > 0) {
      final String lastDir=dirs.get(i - 1);
      final String dir=dirs.get(i);
      if ("String_Node_Str".equals(dir) && !("String_Node_Str".equals(lastDir))) {
        dirs.remove(i);
        dirs.remove(i - 1);
        dirNum=dirs.size();
        i=i - 1;
        continue;
      }
    }
    i++;
  }
  final StringBuffer buff=new StringBuffer(p.length());
  if (p.startsWith(separator + separator)) {
    buff.append(separator).append(separator);
  }
 else   if (p.startsWith(separator)) {
    buff.append(separator);
  }
  final Iterator<String> iter=dirs.iterator();
  while (iter.hasNext()) {
    buff.append(iter.next());
    if (iter.hasNext()) {
      buff.append(separator);
    }
  }
  if (p.endsWith(separator)) {
    buff.append(separator);
  }
  return buff.toString();
}
Program: 100782
Project: 100782
Buggy source:
FileInfo(final String file){
  this.uri=toURI(new File(file));
  this.file=file;
}

Fixed version (ground truth):
FileInfo(final String file){
  if (file == null)   throw new IllegalArgumentException(new NullPointerException());
  this.uri=toURI(new File(file));
  this.file=file;
}
Program: 100783
Project: 100783
Buggy source:
private FileInfo getOrAdd(final String f){
  FileInfo i=files.get(f);
  if (i == null) {
    i=new FileInfo(f);
    files.put(f,i);
  }
  return i;
}

Fixed version (ground truth):
/** 
 * Get or create FileInfo for given path.
 * @param file system path
 */
private FileInfo getOrAdd(final String file){
  final String f=FileUtils.normalize(file);
  FileInfo i=files.get(f);
  if (i == null) {
    i=new FileInfo(f);
    files.put(f,i);
  }
  return i;
}
Program: 100784
Project: 100784
Buggy source:
public FileInfo build(){
  if (uri == null && file == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  final FileInfo fi=uri != null ? new FileInfo(uri) : new FileInfo(file);
  fi.format=format;
  fi.hasConref=hasConref;
  fi.isChunked=isChunked;
  fi.hasLink=hasLink;
  fi.isResourceOnly=isResourceOnly;
  fi.isTarget=isTarget;
  fi.isConrefTarget=isConrefTarget;
  fi.isNonConrefTarget=isNonConrefTarget;
  fi.isConrefPush=isConrefPush;
  fi.hasKeyref=hasKeyref;
  fi.hasCoderef=hasCoderef;
  fi.isSubjectScheme=isSubjectScheme;
  fi.isSkipChunk=isSkipChunk;
  fi.isSubtarget=isSubtarget;
  fi.isFlagImage=isFlagImage;
  fi.isChunkedDitaMap=isChunkedDitaMap;
  fi.isOutDita=isOutDita;
  fi.isCopyToSource=isCopyToSource;
  fi.isActive=isActive;
  return fi;
}

Fixed version (ground truth):
public FileInfo build(){
  if (uri == null && file == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  final FileInfo fi=uri != null ? new FileInfo(uri) : new FileInfo(file);
  fi.format=format;
  fi.hasConref=hasConref;
  fi.isChunked=isChunked;
  fi.hasLink=hasLink;
  fi.isResourceOnly=isResourceOnly;
  fi.isTarget=isTarget;
  fi.isConrefTarget=isConrefTarget;
  fi.isNonConrefTarget=isNonConrefTarget;
  fi.isConrefPush=isConrefPush;
  fi.hasKeyref=hasKeyref;
  fi.hasCoderef=hasCoderef;
  fi.isSubjectScheme=isSubjectScheme;
  fi.isSkipChunk=isSkipChunk;
  fi.isSubtarget=isSubtarget;
  fi.isFlagImage=isFlagImage;
  fi.isChunkedDitaMap=isChunkedDitaMap;
  fi.isOutDita=isOutDita;
  fi.isCopyToSource=isCopyToSource;
  fi.isActive=isActive;
  return fi;
}
Program: 100785
Project: 100785
Buggy source:
/** 
 * Convert URI references to file paths.
 * @param filename file reference
 * @return file path
 */
private static File toFile(final String filename){
  if (filename == null) {
    return null;
  }
  String f=filename;
  try {
    f=URLDecoder.decode(filename,UTF8);
  }
 catch (  final UnsupportedEncodingException e) {
    throw new RuntimeException(e);
  }
  if (processingMode == Mode.LAX) {
    f=f.replace(WINDOWS_SEPARATOR,File.separator);
  }
  f=f.replace(URI_SEPARATOR,File.separator);
  return new File(f);
}

Fixed version (ground truth):
/** 
 * Convert URI or chimera references to file paths.
 * @param filename file reference
 * @return file path
 */
private static File toFile(final String filename){
  if (filename == null) {
    return null;
  }
  String f=filename;
  try {
    f=URLDecoder.decode(filename,UTF8);
  }
 catch (  final UnsupportedEncodingException e) {
    throw new RuntimeException(e);
  }
  f=f.replace(WINDOWS_SEPARATOR,File.separator).replace(UNIX_SEPARATOR,File.separator);
  return new File(f);
}
Program: 100790
Project: 100790
Buggy source:
/** 
 * Task execute point.
 * @throws BuildException exception
 * @see org.apache.tools.ant.taskdefs.Echo#execute()
 */
@Override public void execute() throws BuildException {
  final ArrayList<String> prop=new ArrayList<String>();
  for (  final Param p : params) {
    if (!p.isValid()) {
      throw new BuildException("String_Node_Str");
    }
    final String ifProperty=p.getIf();
    final String unlessProperty=p.getUnless();
    if ((ifProperty == null || getProject().getProperties().containsKey(ifProperty)) && (unlessProperty == null || !getProject().getProperties().containsKey(unlessProperty))) {
      final int idx=Integer.parseInt(p.getName()) - 1;
      prop.set(idx,p.getValue());
    }
  }
  logger=new DITAOTAntLogger(getProject());
  final MessageBean msgBean=MessageUtils.getInstance().getMessage(id,prop.toArray(new String[prop.size()]));
  if (msgBean != null) {
    final String type=msgBean.getType();
    if (ERROR.equals(type)) {
      logger.logError(msgBean.toString());
    }
 else     if (WARN.equals(type)) {
      logger.logWarn(msgBean.toString());
    }
 else     if (INFO.equals(type)) {
      logger.logInfo(msgBean.toString());
    }
 else     if (DEBUG.equals(type)) {
      logger.logDebug(msgBean.toString());
    }
  }
}

Fixed version (ground truth):
/** 
 * Task execute point.
 * @throws BuildException exception
 * @see org.apache.tools.ant.taskdefs.Echo#execute()
 */
@Override public void execute() throws BuildException {
  logger=new DITAOTAntLogger(getProject());
  final MessageBean msgBean=MessageUtils.getInstance().getMessage(id,readParamValues());
  if (msgBean != null) {
    final String type=msgBean.getType();
    if (ERROR.equals(type)) {
      logger.logError(msgBean.toString());
    }
 else     if (WARN.equals(type)) {
      logger.logWarn(msgBean.toString());
    }
 else     if (INFO.equals(type)) {
      logger.logInfo(msgBean.toString());
    }
 else     if (DEBUG.equals(type)) {
      logger.logDebug(msgBean.toString());
    }
  }
}
Program: 100791
Project: 100791
Buggy source:
/** 
 * Task execute point.
 * @throws BuildException exception
 * @see org.apache.tools.ant.taskdefs.Exit#execute()
 */
@Override public void execute() throws BuildException {
  final boolean fail=nestedConditionPresent() ? testNestedCondition() : (testIfCondition() && testUnlessCondition());
  if (!fail) {
    return;
  }
  if (id == null) {
    throw new BuildException("String_Node_Str");
  }
  final ArrayList<String> prop=new ArrayList<String>();
  for (  final Param p : params) {
    if (!p.isValid()) {
      throw new BuildException("String_Node_Str");
    }
    final String ifProperty=p.getIf();
    final String unlessProperty=p.getUnless();
    if ((ifProperty == null || getProject().getProperties().containsKey(ifProperty)) && (unlessProperty == null || !getProject().getProperties().containsKey(unlessProperty))) {
      final int idx=Integer.parseInt(p.getName()) - 1;
      prop.set(idx,p.getValue());
    }
  }
  final MessageBean msgBean=MessageUtils.getInstance().getMessage(id,prop.toArray(new String[prop.size()]));
  final DITAOTLogger logger=new DITAOTAntLogger(getProject());
  if (msgBean != null) {
    final String type=msgBean.getType();
    if (FATAL.equals(type)) {
      setMessage(msgBean.toString());
      try {
        super.execute();
      }
 catch (      final BuildException ex) {
        throw new BuildException(msgBean.toString(),new DITAOTException(msgBean,ex,msgBean.toString()));
      }
    }
 else     if (ERROR.equals(type)) {
      logger.logError(msgBean.toString());
    }
 else     if (WARN.equals(type)) {
      logger.logWarn(msgBean.toString());
    }
 else     if (INFO.equals(type)) {
      logger.logInfo(msgBean.toString());
    }
 else     if (DEBUG.equals(type)) {
      logger.logDebug(msgBean.toString());
    }
  }
}

Fixed version (ground truth):
/** 
 * Task execute point.
 * @throws BuildException exception
 * @see org.apache.tools.ant.taskdefs.Exit#execute()
 */
@Override public void execute() throws BuildException {
  final boolean fail=nestedConditionPresent() ? testNestedCondition() : (testIfCondition() && testUnlessCondition());
  if (!fail) {
    return;
  }
  if (id == null) {
    throw new BuildException("String_Node_Str");
  }
  final MessageBean msgBean=MessageUtils.getInstance().getMessage(id,readParamValues());
  final DITAOTLogger logger=new DITAOTAntLogger(getProject());
  if (msgBean != null) {
    final String type=msgBean.getType();
    if (FATAL.equals(type)) {
      setMessage(msgBean.toString());
      try {
        super.execute();
      }
 catch (      final BuildException ex) {
        throw new BuildException(msgBean.toString(),new DITAOTException(msgBean,ex,msgBean.toString()));
      }
    }
 else     if (ERROR.equals(type)) {
      logger.logError(msgBean.toString());
    }
 else     if (WARN.equals(type)) {
      logger.logWarn(msgBean.toString());
    }
 else     if (INFO.equals(type)) {
      logger.logInfo(msgBean.toString());
    }
 else     if (DEBUG.equals(type)) {
      logger.logDebug(msgBean.toString());
    }
  }
}
Program: 100792
Project: 100792
Buggy source:
/** 
 * Read temporary configuration files. If configuration files are not found, assume an empty job object is being created.
 * @throws IOException if reading configuration files failed
 * @throws SAXException if XML parsing failed
 * @throws IllegalStateException if configuration files are missing
 */
private void read() throws IOException {
  final File jobFile=new File(tempDir,JOB_FILE);
  if (jobFile.exists()) {
    try {
      XMLReader parser=StringUtils.getXMLReader();
      parser.setContentHandler(new JobHandler(prop));
      parser.parse(jobFile.toURI().toString());
    }
 catch (    final SAXException e) {
      throw new IOException("String_Node_Str" + e.getMessage());
    }
    return;
  }
  final Properties p=new Properties();
  final File ditalist=new File(tempDir,FILE_NAME_DITA_LIST);
  final File xmlDitalist=new File(tempDir,FILE_NAME_DITA_LIST_XML);
  InputStream in=null;
  try {
    if (xmlDitalist.exists()) {
      in=new FileInputStream(xmlDitalist);
      p.loadFromXML(in);
    }
 else     if (ditalist.exists()) {
      in=new FileInputStream(ditalist);
      p.load(in);
    }
  }
 catch (  final IOException e) {
    throw new IOException("String_Node_Str" + e.getMessage());
  }
 finally {
    if (in != null) {
      try {
        in.close();
      }
 catch (      final IOException e) {
        throw new IOException("String_Node_Str" + e.getMessage());
      }
    }
  }
  readProperties(p);
}

Fixed version (ground truth):
/** 
 * Read temporary configuration files. If configuration files are not found, assume an empty job object is being created.
 * @throws IOException if reading configuration files failed
 * @throws SAXException if XML parsing failed
 * @throws IllegalStateException if configuration files are missing
 */
private void read() throws IOException {
  final File jobFile=new File(tempDir,JOB_FILE);
  if (jobFile.exists()) {
    InputStream in=null;
    try {
      XMLReader parser=StringUtils.getXMLReader();
      parser.setContentHandler(new JobHandler(prop));
      in=new FileInputStream(jobFile);
      parser.parse(new InputSource(in));
    }
 catch (    final SAXException e) {
      throw new IOException("String_Node_Str" + e.getMessage());
    }
 finally {
      if (in != null) {
        in.close();
      }
    }
    return;
  }
  final Properties p=new Properties();
  final File ditalist=new File(tempDir,FILE_NAME_DITA_LIST);
  final File xmlDitalist=new File(tempDir,FILE_NAME_DITA_LIST_XML);
  InputStream in=null;
  try {
    if (xmlDitalist.exists()) {
      in=new FileInputStream(xmlDitalist);
      p.loadFromXML(in);
    }
 else     if (ditalist.exists()) {
      in=new FileInputStream(ditalist);
      p.load(in);
    }
  }
 catch (  final IOException e) {
    throw new IOException("String_Node_Str" + e.getMessage());
  }
 finally {
    if (in != null) {
      try {
        in.close();
      }
 catch (      final IOException e) {
        throw new IOException("String_Node_Str" + e.getMessage());
      }
    }
  }
  readProperties(p);
}
Program: 100795
Project: 100795
Buggy source:
/** 
 * Add the given file the wait list if it has not been parsed.
 * @param file relative system path
 */
private void addToWaitList(final File file){
  if (doneList.contains(file) || waitList.contains(file)) {
    return;
  }
  waitList.add(file);
}

Fixed version (ground truth):
/** 
 * Add the given file the wait list if it has not been parsed.
 * @param file relative system path
 */
private void addToWaitList(final File file){
  if (doneList.contains(file) || waitList.contains(file) || file.equals(currentFile)) {
    return;
  }
  waitList.add(file);
}
Program: 100796
Project: 100796
Buggy source:
private void processWaitList() throws DITAOTException {
  reader.setTranstype(transtype);
  if (FileUtils.isDITAMapFile(inputFile.getPath())) {
    reader.setPrimaryDitamap(inputFile.getPath());
  }
  while (!waitList.isEmpty()) {
    processFile(waitList.remove(0));
  }
}

Fixed version (ground truth):
private void processWaitList() throws DITAOTException {
  reader.setTranstype(transtype);
  if (FileUtils.isDITAMapFile(inputFile.getPath())) {
    reader.setPrimaryDitamap(inputFile.getPath());
  }
  while (!waitList.isEmpty()) {
    currentFile=waitList.remove(0);
    processFile(currentFile);
  }
}
Program: 100797
Project: 100797
Buggy source:
@Override public void startElement(final String uri,final String localName,final String qName,final Attributes attributes) throws SAXException {
  final String attrValue=attributes.getValue(ATTRIBUTE_NAME_PROCESSING_ROLE);
  if (attrValue != null) {
    processRoleStack.push(attrValue);
    processRoleLevel++;
    if (ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(attrValue)) {
      return;
    }
  }
 else   if (processRoleLevel > 0) {
    processRoleLevel++;
    if (ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(processRoleStack.peek())) {
      return;
    }
  }
  final String classAttr=attributes.getValue(ATTRIBUTE_NAME_CLASS);
  handleSpecialization(localName,classAttr);
  parseTopic(localName,attributes.getValue(ATTRIBUTE_NAME_ID));
  parseIndexTerm(localName,attributes);
  parseIndexSee(localName);
  parseIndexSeeAlso(localName);
  if (IndexTerm.getTermLocale() == null) {
    final String xmlLang=attributes.getValue(ATTRIBUTE_NAME_XML_LANG);
    if (xmlLang != null) {
      IndexTerm.setTermLocale(StringUtils.getLocale(xmlLang));
    }
  }
  if (titleSpecList.contains(localName) && !titleMap.containsKey(topicIdStack.peek())) {
    inTitleElement=true;
    title=null;
  }
  if (indexSortAsSpecList.contains(localName)) {
    insideSortingAs=true;
  }
}

Fixed version (ground truth):
@Override public void startElement(final String uri,final String localName,final String qName,final Attributes attributes) throws SAXException {
  final String attrValue=attributes.getValue(ATTRIBUTE_NAME_PROCESSING_ROLE);
  if (attrValue != null) {
    processRoleStack.push(attrValue);
    processRoleLevel++;
    if (ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(attrValue)) {
      return;
    }
  }
 else   if (processRoleLevel > 0) {
    processRoleLevel++;
    if (ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(processRoleStack.peek())) {
      return;
    }
  }
  final String classAttr=attributes.getValue(ATTRIBUTE_NAME_CLASS);
  handleSpecialization(localName,classAttr);
  parseTopic(localName,attributes.getValue(ATTRIBUTE_NAME_ID));
  parseIndexTerm(localName,attributes);
  parseIndexSee(localName);
  parseIndexSeeAlso(localName);
  if (IndexTerm.getTermLocale() == null) {
    final String xmlLang=attributes.getValue(ATTRIBUTE_NAME_XML_LANG);
    if (xmlLang != null) {
      IndexTerm.setTermLocale(StringUtils.getLocale(xmlLang));
    }
  }
  if (titleSpecList.contains(localName) && !topicIdStack.empty() && !titleMap.containsKey(topicIdStack.peek())) {
    inTitleElement=true;
    title=null;
  }
  if (indexSortAsSpecList.contains(localName)) {
    insideSortingAs=true;
  }
}
Program: 100799
Project: 100799
Buggy source:
/** 
 * Rewrite local non-DITA href value. <p>TODO: return type should be   {@link java.util.URI}.</p>
 * @param attValue href attribute value
 * @return rewritten href value
 */
private String handleLocalHref(final String attValue){
  return FileUtils.resolveTopic(new File(filePath).getParent(),attValue);
}

Fixed version (ground truth):
/** 
 * Rewrite local non-DITA href value. <p>TODO: return type should be   {@link java.util.URI}.</p>
 * @param attValue href attribute value
 * @return rewritten href value
 */
private String handleLocalHref(final String attValue){
  final File parentFile=new File(filePath).getParentFile();
  if (parentFile != null) {
    final URI d=new File(dirPath).toURI();
    final URI p=new File(dirPath,filePath).getParentFile().toURI();
    final String b=d.relativize(p).toASCIIString();
    final StringBuilder ret=new StringBuilder(b);
    if (!b.endsWith(URI_SEPARATOR)) {
      ret.append(URI_SEPARATOR);
    }
    ret.append(attValue);
    return FileUtils.normalize(ret.toString(),URI_SEPARATOR);
  }
 else {
    return attValue;
  }
}
Program: 100800
Project: 100800
Buggy source:
@Test public void testParse() throws Exception {
  final MergeTopicParser parser=new MergeTopicParser(new MergeUtils());
  final ByteArrayOutputStream output=new ByteArrayOutputStream();
  final TransformerHandler s=stf.newTransformerHandler();
  s.getTransformer().setOutputProperty(OMIT_XML_DECLARATION,"String_Node_Str");
  s.setResult(new StreamResult(output));
  parser.setContentHandler(s);
  parser.setLogger(new TestUtils.TestLogger());
  s.startDocument();
  parser.parse("String_Node_Str",srcDir.getAbsolutePath());
  s.endDocument();
  assertXMLEqual(new InputSource(new File(expDir,"String_Node_Str").toURI().toString()),new InputSource(new ByteArrayInputStream(output.toByteArray())));
}

Fixed version (ground truth):
@Test public void testParse() throws Exception {
  final MergeTopicParser parser=new MergeTopicParser(new MergeUtils());
  final ByteArrayOutputStream output=new ByteArrayOutputStream();
  final TransformerHandler s=stf.newTransformerHandler();
  s.getTransformer().setOutputProperty(OMIT_XML_DECLARATION,"String_Node_Str");
  s.setResult(new StreamResult(output));
  parser.setContentHandler(s);
  parser.setLogger(new TestUtils.TestLogger());
  s.startDocument();
  parser.parse("String_Node_Str",srcDir.getAbsolutePath());
  s.endDocument();
  assertXMLEqual(new InputSource(new File(expDir,"String_Node_Str").toURI().toString()),new InputSource(new ByteArrayInputStream(output.toByteArray())));
  final Method method=MergeTopicParser.class.getDeclaredMethod("String_Node_Str",String.class);
  method.setAccessible(true);
  assertEquals("String_Node_Str",method.invoke(parser,"String_Node_Str"));
}
Program: 100801
Project: 100801
Buggy source:
@Override public void characters(final char[] ch,final int start,final int length) throws SAXException {
  final StringBuilder tempBuf=new StringBuilder(length);
  tempBuf.append(ch,start,length);
  normalizeAndCollapseWhitespace(tempBuf);
  String temp=tempBuf.toString();
  if (processRoleStack.isEmpty() || !ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equalsIgnoreCase(processRoleStack.peek())) {
    if (!insideSortingAs && !termStack.empty()) {
      final IndexTerm indexTerm=termStack.peek();
      temp=StringUtils.escapeXML(temp);
      temp=trimSpaceAtStart(temp,indexTerm.getTermName());
      indexTerm.setTermName(StringUtils.setOrAppend(indexTerm.getTermName(),temp,false));
    }
 else     if (insideSortingAs && temp.length() > 0) {
      final IndexTerm indexTerm=termStack.peek();
      temp=StringUtils.escapeXML(temp);
      temp=trimSpaceAtStart(temp,indexTerm.getTermKey());
      indexTerm.setTermKey(StringUtils.setOrAppend(indexTerm.getTermKey(),temp,false));
    }
 else     if (inTitleElement) {
      temp=StringUtils.escapeXML(temp);
      temp=trimSpaceAtStart(temp,title);
      title=StringUtils.setOrAppend(title,temp,false);
    }
  }
}

Fixed version (ground truth):
@Override public void characters(final char[] ch,final int start,final int length) throws SAXException {
  final StringBuilder tempBuf=new StringBuilder(length);
  tempBuf.append(ch,start,length);
  normalizeAndCollapseWhitespace(tempBuf);
  String temp=tempBuf.toString();
  if (processRoleStack.isEmpty() || !ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equalsIgnoreCase(processRoleStack.peek())) {
    if (!insideSortingAs && !termStack.empty()) {
      final IndexTerm indexTerm=termStack.peek();
      temp=trimSpaceAtStart(temp,indexTerm.getTermName());
      indexTerm.setTermName(StringUtils.setOrAppend(indexTerm.getTermName(),temp,false));
    }
 else     if (insideSortingAs && temp.length() > 0) {
      final IndexTerm indexTerm=termStack.peek();
      temp=trimSpaceAtStart(temp,indexTerm.getTermKey());
      indexTerm.setTermKey(StringUtils.setOrAppend(indexTerm.getTermKey(),temp,false));
    }
 else     if (inTitleElement) {
      temp=trimSpaceAtStart(temp,title);
      title=StringUtils.setOrAppend(title,temp,false);
    }
  }
}