Program: 100621
Project: 100621
Buggy source:
/** 
 * Rewrite local DITA href value.
 * @param href href attribute value
 * @return rewritten href value
 */
private URI handleLocalDita(final URI href,final AttributesImpl atts){
  final URI attValue=href;
  final int sharpIndex=attValue.toString().indexOf(SHARP);
  URI pathFromMap;
  URI retAttValue;
  if (sharpIndex != -1) {
    if (sharpIndex == 0) {
      pathFromMap=toURI(filePath);
    }
 else {
      pathFromMap=toURI(filePath).resolve(attValue.toString().substring(0,sharpIndex));
    }
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,toURI(pathFromMap + attValue.toString().substring(sharpIndex)).toString());
    final String topicID=getTopicID(attValue.getFragment());
    final int index=attValue.toString().indexOf(SLASH,sharpIndex);
    final String elementId=index != -1 ? attValue.toString().substring(index) : "String_Node_Str";
    final URI pathWithTopicID=setFragment(dirPath.toURI().resolve(pathFromMap),topicID);
    if (util.findId(pathWithTopicID)) {
      retAttValue=toURI(SHARP + util.getIdValue(pathWithTopicID) + elementId);
    }
 else {
      retAttValue=toURI(SHARP + util.addId(pathWithTopicID) + elementId);
    }
  }
 else {
    pathFromMap=toURI(filePath).resolve(attValue.toString());
    URI absolutePath=dirPath.toURI().resolve(pathFromMap);
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,pathFromMap.toString());
    if (util.findId(absolutePath)) {
      retAttValue=toURI(SHARP + util.getIdValue(pathFromMap));
    }
 else {
      final String fileId=MergeUtils.getFirstTopicId(absolutePath,dirPath,false);
      final URI key=setFragment(absolutePath,fileId);
      if (util.findId(key)) {
        util.addId(absolutePath,util.getIdValue(key));
        retAttValue=toURI(SHARP + util.getIdValue(key));
      }
 else {
        retAttValue=toURI(SHARP + util.addId(absolutePath));
        util.addId(key,util.getIdValue(absolutePath));
      }
    }
  }
  return retAttValue;
}

Fixed version (ground truth):
/** 
 * Rewrite local DITA href value.
 * @param href href attribute value
 * @return rewritten href value
 */
private URI handleLocalDita(final URI href,final AttributesImpl atts){
  final URI attValue=href;
  final int sharpIndex=attValue.toString().indexOf(SHARP);
  URI pathFromMap;
  URI retAttValue;
  if (sharpIndex != -1) {
    if (sharpIndex == 0) {
      pathFromMap=toURI(filePath);
    }
 else {
      pathFromMap=toURI(filePath).resolve(attValue.toString().substring(0,sharpIndex));
    }
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,toURI(pathFromMap + attValue.toString().substring(sharpIndex)).toString());
    final String topicID=getTopicID(attValue.getFragment());
    final int index=attValue.toString().indexOf(SLASH,sharpIndex);
    final String elementId=index != -1 ? attValue.toString().substring(index) : "String_Node_Str";
    final URI pathWithTopicID=setFragment(dirPath.toURI().resolve(pathFromMap),topicID);
    if (util.findId(pathWithTopicID)) {
      retAttValue=toURI(SHARP + util.getIdValue(pathWithTopicID) + elementId);
    }
 else {
      retAttValue=toURI(SHARP + util.addId(pathWithTopicID) + elementId);
    }
  }
 else {
    pathFromMap=toURI(filePath).resolve(attValue.toString());
    URI absolutePath=dirPath.toURI().resolve(pathFromMap);
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,pathFromMap.toString());
    if (util.findId(absolutePath)) {
      retAttValue=toURI(SHARP + util.getIdValue(absolutePath));
    }
 else {
      final String fileId=MergeUtils.getFirstTopicId(absolutePath,dirPath,false);
      final URI key=setFragment(absolutePath,fileId);
      if (util.findId(key)) {
        util.addId(absolutePath,util.getIdValue(key));
        retAttValue=toURI(SHARP + util.getIdValue(key));
      }
 else {
        retAttValue=toURI(SHARP + util.addId(absolutePath));
        util.addId(key,util.getIdValue(absolutePath));
      }
    }
  }
  return retAttValue;
}