Program: 100804
Project: 100804
Buggy source:
/** 
 * Rewrite local DITA href value.
 * @param sharpIndex hash char index
 * @param attValue href attribute value
 * @return rewritten href value
 */
private String handleLocalDita(final int sharpIndex,final String attValue,final AttributesImpl atts){
  String pathFromMap;
  String retAttValue=attValue;
  if (sharpIndex != -1) {
    if (sharpIndex == 0) {
      pathFromMap=FileUtils.separatorsToUnix(filePath);
    }
 else {
      pathFromMap=FileUtils.separatorsToUnix(FileUtils.resolveTopic(new File(filePath).getParent(),attValue.substring(0,sharpIndex)));
    }
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,pathFromMap + attValue.substring(sharpIndex));
    String topicId=attValue.substring(sharpIndex);
    final int slashIndex=topicId.indexOf(SLASH);
    final int index=attValue.indexOf(SLASH,sharpIndex);
    topicId=slashIndex != -1 ? pathFromMap + topicId.substring(0,slashIndex) : pathFromMap + topicId;
    if (util.findId(topicId)) {
      final String prefix=SHARP + util.getIdValue(topicId);
      retAttValue=index != -1 ? prefix + attValue.substring(index) : prefix;
    }
 else {
      final String prefix=SHARP + util.addId(topicId);
      retAttValue=index != -1 ? prefix + attValue.substring(index) : prefix;
    }
  }
 else {
    pathFromMap=FileUtils.resolveTopic(new File(filePath).getParent(),attValue);
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,pathFromMap);
    if (util.findId(pathFromMap)) {
      retAttValue=SHARP + util.getIdValue(pathFromMap);
    }
 else {
      final String fileId=MergeUtils.getFirstTopicId(pathFromMap,dirPath,false);
      final String key=pathFromMap + SHARP + fileId;
      if (util.findId(key)) {
        util.addId(pathFromMap,util.getIdValue(key));
        retAttValue=SHARP + util.getIdValue(key);
      }
 else {
        retAttValue=SHARP + util.addId(pathFromMap);
        util.addId(key,util.getIdValue(pathFromMap));
      }
    }
  }
  return retAttValue;
}

Fixed version (ground truth):
/** 
 * Rewrite local DITA href value. <p>TODO: return type should be   {@link java.util.URI}.</p>
 * @param sharpIndex hash char index
 * @param attValue href attribute value
 * @return rewritten href value
 */
private String handleLocalDita(final int sharpIndex,final String attValue,final AttributesImpl atts){
  String pathFromMap;
  String retAttValue=attValue;
  if (sharpIndex != -1) {
    if (sharpIndex == 0) {
      pathFromMap=FileUtils.separatorsToUnix(filePath);
    }
 else {
      pathFromMap=FileUtils.separatorsToUnix(FileUtils.resolveTopic(new File(filePath).getParent(),attValue.substring(0,sharpIndex)));
    }
    pathFromMap=URLUtils.decode(pathFromMap);
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,URLUtils.clean(pathFromMap + attValue.substring(sharpIndex)));
    String topicId=attValue.substring(sharpIndex);
    final int slashIndex=topicId.indexOf(SLASH);
    final int index=attValue.indexOf(SLASH,sharpIndex);
    topicId=slashIndex != -1 ? pathFromMap + topicId.substring(0,slashIndex) : pathFromMap + topicId;
    if (util.findId(topicId)) {
      final String prefix=SHARP + util.getIdValue(topicId);
      retAttValue=index != -1 ? prefix + attValue.substring(index) : prefix;
    }
 else {
      final String prefix=SHARP + util.addId(topicId);
      retAttValue=index != -1 ? prefix + attValue.substring(index) : prefix;
    }
  }
 else {
    pathFromMap=FileUtils.resolveTopic(new File(filePath).getParent(),attValue);
    pathFromMap=URLUtils.decode(pathFromMap);
    XMLUtils.addOrSetAttribute(atts,ATTRIBUTE_NAME_OHREF,URLUtils.clean(pathFromMap));
    if (util.findId(pathFromMap)) {
      retAttValue=SHARP + util.getIdValue(pathFromMap);
    }
 else {
      final String fileId=MergeUtils.getFirstTopicId(pathFromMap,dirPath,false);
      final String key=pathFromMap + SHARP + fileId;
      if (util.findId(key)) {
        util.addId(pathFromMap,util.getIdValue(key));
        retAttValue=SHARP + util.getIdValue(key);
      }
 else {
        retAttValue=SHARP + util.addId(pathFromMap);
        util.addId(key,util.getIdValue(pathFromMap));
      }
    }
  }
  return URLUtils.clean(retAttValue);
}