Program: 100772
Project: 100772
Buggy source:
@Override public void startElement(final String uri,final String localName,final String qName,final Attributes atts) throws SAXException {
  final String classValue=atts.getValue(ATTRIBUTE_NAME_CLASS);
  final String idValue=atts.getValue(ATTRIBUTE_NAME_ID);
  if (skip && skipLevel > 0) {
    skipLevel++;
  }
  try {
    if (classValue != null && TOPIC_TOPIC.matches(classValue)) {
      topicSpecSet.add(qName);
      final String id=atts.getValue(ATTRIBUTE_NAME_ID);
      final Element element=DITAAttrUtils.getInstance().searchForNode(topicDoc,id,ATTRIBUTE_NAME_ID,TOPIC_TOPIC.matcher);
      if (separate && include && !ATTR_CHUNK_VALUE_SELECT_TOPIC.equals(selectMethod)) {
        fileWriterStack.push(output);
        outputFileNameStack.push(outputFile);
        File newFileName=FileUtils.resolveFile(filePath,idValue + FILE_EXTENSION_DITA);
        if (StringUtils.isEmptyString(idValue) || newFileName.exists()) {
          final File t=newFileName;
          newFileName=FileUtils.resolveFile(filePath,generateFilename());
          conflictTable.put(newFileName.getPath(),t.getPath());
        }
        outputFile=newFileName;
        output=new OutputStreamWriter(new FileOutputStream(newFileName),UTF8);
        writeStartDocument(output);
        if (OS_NAME.toLowerCase().indexOf(OS_NAME_WINDOWS) == -1) {
          writeProcessingInstruction(output,PI_WORKDIR_TARGET,filePath.getAbsolutePath());
        }
 else {
          writeProcessingInstruction(output,PI_WORKDIR_TARGET,UNIX_SEPARATOR + filePath);
        }
        writeProcessingInstruction(output,PI_WORKDIR_TARGET_URI,filePath.toURI().toString());
        changeTable.put(newFileName.getPath(),newFileName.getPath());
        if (idValue != null) {
          changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(newFileName.getPath(),idValue));
        }
 else {
          changeTable.put(currentParsingFile.getPath(),newFileName.getPath());
        }
        final Element newChild=elem.getOwnerDocument().createElement(MAP_TOPICREF.localName);
        newChild.setAttribute(ATTRIBUTE_NAME_HREF,toURI(FileUtils.getRelativePath(new File(filePath,FILE_NAME_STUB_DITAMAP),newFileName)).toString());
        newChild.setAttribute(ATTRIBUTE_NAME_CLASS,MAP_TOPICREF.toString());
        newChild.setAttribute(ATTRIBUTE_NAME_XTRF,ATTR_XTRF_VALUE_GENERATED);
        createTopicMeta(element,newChild);
        if (stub != null) {
          if (includelevel == 0 && siblingStub != null) {
            siblingStub.getParentNode().insertBefore(newChild,siblingStub);
          }
 else {
            stub.getParentNode().insertBefore(newChild,stub);
          }
          stubStack.push(stub);
          stub=(Element)stub.cloneNode(false);
          newChild.appendChild(stub);
        }
      }
      if (include && ATTR_CHUNK_VALUE_SELECT_TOPIC.equals(selectMethod)) {
        include=false;
        skipLevel=1;
        skip=true;
      }
 else       if (include) {
        if (!currentParsingFile.equals(outputFile)) {
          if (idValue != null) {
            changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(outputFile.getPath(),idValue));
          }
 else {
            changeTable.put(currentParsingFile.getPath(),outputFile.getPath());
          }
        }
      }
 else       if (skip) {
        skipLevel=1;
      }
 else       if (!include && idValue != null && (idValue.equals(targetTopicId) || startFromFirstTopic)) {
        include=true;
        includelevel=0;
        skip=false;
        skipLevel=0;
        startFromFirstTopic=false;
        if (!currentParsingFile.equals(outputFile)) {
          changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(outputFile.getPath(),idValue));
        }
      }
    }
    if (include) {
      includelevel++;
      final AttributesImpl resAtts=new AttributesImpl(atts);
      for (int i=0; i < resAtts.getLength(); i++) {
        final String attrName=resAtts.getQName(i);
        String attrValue=resAtts.getValue(i);
        if (ATTRIBUTE_NAME_ID.equals(attrName) && TOPIC_TOPIC.matches(classValue)) {
          if (topicID.contains(attrValue)) {
            final String oldAttrValue=attrValue;
            attrValue=chunkFilenameGenerator.generateID();
            topicID.add(attrValue);
            String tmpVal=changeTable.get(setFragment(currentParsingFile.getPath(),idValue));
            if (tmpVal != null && tmpVal.equalsIgnoreCase(setFragment(outputFile.getPath(),idValue))) {
              changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(outputFile.getPath(),attrValue));
            }
            tmpVal=changeTable.get(currentParsingFile);
            if (tmpVal != null && tmpVal.equalsIgnoreCase(setFragment(outputFile.getPath(),idValue))) {
              changeTable.put(currentParsingFile.getPath(),setFragment(outputFile.getPath(),attrValue));
            }
            currentParsingFileTopicIDChangeTable.put(oldAttrValue,attrValue);
          }
 else {
            topicID.add(attrValue);
          }
        }
        String value=attrValue;
        if (ATTRIBUTE_NAME_HREF.equals(attrName)) {
          if (checkHREF(resAtts)) {
            String relative=FileUtils.getRelativeUnixPath(outputFile,currentParsingFile.getPath());
            if (conflictTable.containsKey(outputFile)) {
              final String realoutputfile=conflictTable.get(outputFile);
              relative=FileUtils.getRelativeUnixPath(realoutputfile,currentParsingFile.getPath());
            }
            if (attrValue.startsWith(SHARP)) {
              value=relative + attrValue;
            }
 else             if (relative.indexOf(SLASH) != -1) {
              relative=relative.substring(0,relative.lastIndexOf(SLASH));
              value=FileUtils.resolveTopic(relative,attrValue);
            }
 else {
            }
          }
 else {
          }
        }
        resAtts.setValue(i,value);
      }
      if (classValue != null && TOPIC_TOPIC.matches(classValue) && resAtts.getValue("String_Node_Str") == null) {
        XMLUtils.addOrSetAttribute(resAtts,ATTRIBUTE_NAMESPACE_PREFIX_DITAARCHVERSION,ditaarchNSValue);
      }
      writeStartElement(output,qName,resAtts);
    }
  }
 catch (  final Exception e) {
    logger.logError(e.getMessage(),e);
  }
}

Fixed version (ground truth):
@Override public void startElement(final String uri,final String localName,final String qName,final Attributes atts) throws SAXException {
  final String classValue=atts.getValue(ATTRIBUTE_NAME_CLASS);
  final String idValue=atts.getValue(ATTRIBUTE_NAME_ID);
  if (skip && skipLevel > 0) {
    skipLevel++;
  }
  try {
    if (classValue != null && TOPIC_TOPIC.matches(classValue)) {
      topicSpecSet.add(qName);
      final String id=atts.getValue(ATTRIBUTE_NAME_ID);
      final Element element=DITAAttrUtils.getInstance().searchForNode(topicDoc,id,ATTRIBUTE_NAME_ID,TOPIC_TOPIC.matcher);
      if (separate && include && !ATTR_CHUNK_VALUE_SELECT_TOPIC.equals(selectMethod)) {
        fileWriterStack.push(output);
        outputFileNameStack.push(outputFile);
        File newFileName=FileUtils.resolveFile(filePath,idValue + FILE_EXTENSION_DITA);
        if (StringUtils.isEmptyString(idValue) || newFileName.exists()) {
          final File t=newFileName;
          newFileName=FileUtils.resolveFile(filePath,generateFilename());
          conflictTable.put(newFileName.getPath(),t.getPath());
        }
        outputFile=newFileName;
        output=new OutputStreamWriter(new FileOutputStream(newFileName),UTF8);
        writeStartDocument(output);
        if (OS_NAME.toLowerCase().indexOf(OS_NAME_WINDOWS) == -1) {
          writeProcessingInstruction(output,PI_WORKDIR_TARGET,filePath.getAbsolutePath());
        }
 else {
          writeProcessingInstruction(output,PI_WORKDIR_TARGET,UNIX_SEPARATOR + filePath);
        }
        writeProcessingInstruction(output,PI_WORKDIR_TARGET_URI,filePath.toURI().toString());
        changeTable.put(newFileName.getPath(),newFileName.getPath());
        if (idValue != null) {
          changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(newFileName.getPath(),idValue));
        }
 else {
          changeTable.put(currentParsingFile.getPath(),newFileName.getPath());
        }
        final Element newChild=elem.getOwnerDocument().createElement(MAP_TOPICREF.localName);
        newChild.setAttribute(ATTRIBUTE_NAME_HREF,toURI(FileUtils.getRelativePath(new File(filePath,FILE_NAME_STUB_DITAMAP),newFileName)).toString());
        newChild.setAttribute(ATTRIBUTE_NAME_CLASS,MAP_TOPICREF.toString());
        newChild.setAttribute(ATTRIBUTE_NAME_XTRF,ATTR_XTRF_VALUE_GENERATED);
        createTopicMeta(element,newChild);
        if (stub != null) {
          if (includelevel == 0 && siblingStub != null) {
            siblingStub.getParentNode().insertBefore(newChild,siblingStub);
          }
 else {
            stub.getParentNode().insertBefore(newChild,stub);
          }
          stubStack.push(stub);
          stub=(Element)stub.cloneNode(false);
          newChild.appendChild(stub);
        }
      }
      if (include && ATTR_CHUNK_VALUE_SELECT_TOPIC.equals(selectMethod)) {
        include=false;
        skipLevel=1;
        skip=true;
      }
 else       if (include) {
        if (!currentParsingFile.equals(outputFile)) {
          if (idValue != null) {
            changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(outputFile.getPath(),idValue));
          }
 else {
            changeTable.put(currentParsingFile.getPath(),outputFile.getPath());
          }
        }
      }
 else       if (skip) {
        skipLevel=1;
      }
 else       if (!include && idValue != null && (idValue.equals(targetTopicId) || startFromFirstTopic)) {
        include=true;
        includelevel=0;
        skip=false;
        skipLevel=0;
        startFromFirstTopic=false;
        if (!currentParsingFile.equals(outputFile)) {
          changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(outputFile.getPath(),idValue));
        }
      }
    }
    if (include) {
      includelevel++;
      final AttributesImpl resAtts=new AttributesImpl(atts);
      for (int i=0; i < resAtts.getLength(); i++) {
        final String attrName=resAtts.getQName(i);
        String attrValue=resAtts.getValue(i);
        if (ATTRIBUTE_NAME_ID.equals(attrName) && TOPIC_TOPIC.matches(classValue)) {
          if (topicID.contains(attrValue)) {
            final String oldAttrValue=attrValue;
            attrValue=chunkFilenameGenerator.generateID();
            topicID.add(attrValue);
            String tmpVal=changeTable.get(setFragment(currentParsingFile.getPath(),idValue));
            if (tmpVal != null && tmpVal.equalsIgnoreCase(setFragment(outputFile.getPath(),idValue))) {
              changeTable.put(setFragment(currentParsingFile.getPath(),idValue),setFragment(outputFile.getPath(),attrValue));
            }
            tmpVal=changeTable.get(currentParsingFile.getPath());
            if (tmpVal != null && tmpVal.equalsIgnoreCase(setFragment(outputFile.getPath(),idValue))) {
              changeTable.put(currentParsingFile.getPath(),setFragment(outputFile.getPath(),attrValue));
            }
            currentParsingFileTopicIDChangeTable.put(oldAttrValue,attrValue);
          }
 else {
            topicID.add(attrValue);
          }
        }
        String value=attrValue;
        if (ATTRIBUTE_NAME_HREF.equals(attrName)) {
          if (checkHREF(resAtts)) {
            String relative=FileUtils.getRelativeUnixPath(outputFile,currentParsingFile.getPath());
            if (conflictTable.containsKey(outputFile.getPath())) {
              final String realoutputfile=conflictTable.get(outputFile.getPath());
              relative=FileUtils.getRelativeUnixPath(realoutputfile,currentParsingFile.getPath());
            }
            if (attrValue.startsWith(SHARP)) {
              value=relative + attrValue;
            }
 else             if (relative.indexOf(SLASH) != -1) {
              relative=relative.substring(0,relative.lastIndexOf(SLASH));
              value=FileUtils.resolveTopic(relative,attrValue);
            }
 else {
            }
          }
 else {
          }
        }
        resAtts.setValue(i,value);
      }
      if (classValue != null && TOPIC_TOPIC.matches(classValue) && resAtts.getValue("String_Node_Str") == null) {
        XMLUtils.addOrSetAttribute(resAtts,ATTRIBUTE_NAMESPACE_PREFIX_DITAARCHVERSION,ditaarchNSValue);
      }
      writeStartElement(output,qName,resAtts);
    }
  }
 catch (  final Exception e) {
    logger.logError(e.getMessage(),e);
  }
}