Program: 100609
Project: 100609
Buggy source:
private void processChunk(final Element topicref,final URI outputFile){
  final URI hrefValue=toURI(getValue(topicref,ATTRIBUTE_NAME_HREF));
  final Collection<String> chunkValue=split(getValue(topicref,ATTRIBUTE_NAME_CHUNK));
  final URI copytoValue=toURI(getValue(topicref,ATTRIBUTE_NAME_COPY_TO));
  final String scopeValue=getCascadeValue(topicref,ATTRIBUTE_NAME_SCOPE);
  final String classValue=getValue(topicref,ATTRIBUTE_NAME_CLASS);
  final String processRoleValue=getCascadeValue(topicref,ATTRIBUTE_NAME_PROCESSING_ROLE);
  URI outputFileName=outputFile;
  Writer tempWriter=null;
  Set<String> tempTopicID=null;
  targetTopicId=null;
  selectMethod=CHUNK_SELECT_DOCUMENT;
  include=false;
  boolean needWriteDitaTag=true;
  try {
    URI parseFilePath;
    if (copytoValue != null && !chunkValue.contains(CHUNK_TO_CONTENT)) {
      if (hrefValue.getFragment() != null) {
        parseFilePath=setFragment(copytoValue,hrefValue.getFragment());
      }
 else {
        parseFilePath=copytoValue;
      }
    }
 else {
      parseFilePath=hrefValue;
    }
    if (parseFilePath != null && !ATTR_SCOPE_VALUE_EXTERNAL.equals(scopeValue)) {
      if (chunkValue.contains(CHUNK_TO_CONTENT)) {
        tempWriter=output;
        tempTopicID=topicID;
        output=new StringWriter();
        topicID=new HashSet<>();
        if (MAP_MAP.matches(classValue)) {
          outputFileName=currentFile.resolve(parseFilePath);
          needWriteDitaTag=false;
        }
 else         if (copytoValue != null) {
          outputFileName=currentFile.resolve(copytoValue);
        }
 else         if (hrefValue != null) {
          if (chunkValue.contains(CHUNK_SELECT_TOPIC) || chunkValue.contains(CHUNK_SELECT_BRANCH)) {
            if (hrefValue.getFragment() != null) {
              outputFileName=currentFile.resolve(hrefValue.getFragment() + FILE_EXTENSION_DITA);
            }
 else {
              final String firstTopic=getFirstTopicId(currentFile.resolve(hrefValue).getPath());
              if (firstTopic != null) {
                outputFileName=currentFile.resolve(firstTopic + FILE_EXTENSION_DITA);
              }
 else {
                outputFileName=currentFile.resolve(hrefValue);
              }
            }
          }
 else {
            outputFileName=currentFile.resolve(hrefValue);
          }
        }
 else {
          outputFileName=generateOutputFile(currentFile);
        }
        if (new File(outputFileName).exists() && !MAP_MAP.matches(classValue)) {
          final URI t=outputFileName;
          outputFileName=generateOutputFile(currentFile);
          conflictTable.put(outputFileName,t);
        }
        changeTable.put(outputFileName,outputFileName);
        final FileInfo fi=generateFileInfo(outputFileName);
        job.add(fi);
      }
      this.outputFile=outputFileName;
      final URI path=currentFile.resolve(parseFilePath);
      URI newpath;
      if (path.getFragment() != null) {
        newpath=setFragment(outputFileName,path.getFragment());
      }
 else {
        final String firstTopicID=getFirstTopicId(new File(path).getAbsolutePath());
        if (firstTopicID != null) {
          newpath=setFragment(outputFileName,firstTopicID);
        }
 else {
          newpath=outputFileName;
        }
      }
      changeTable.put(path,newpath);
      topicref.setAttribute(ATTRIBUTE_NAME_HREF,getRelativePath(currentFile.resolve(FILE_NAME_STUB_DITAMAP),newpath).toString());
      if (parseFilePath.getFragment() != null) {
        targetTopicId=parseFilePath.getFragment();
      }
      final String s=getChunkByToken(chunkValue,"String_Node_Str",null);
      if (s != null) {
        selectMethod=s;
        if (targetTopicId == null) {
          selectMethod=CHUNK_SELECT_DOCUMENT;
        }
      }
      final URI tempPath=currentParsingFile;
      currentParsingFile=currentFile.resolve(parseFilePath);
      if (!ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(processRoleValue)) {
        currentParsingFileTopicIDChangeTable=new HashMap<>();
        logger.info("String_Node_Str" + currentParsingFile);
        reader.parse(currentParsingFile.toString());
        if (currentParsingFileTopicIDChangeTable.size() > 0) {
          final URI href=toURI(topicref.getAttribute(ATTRIBUTE_NAME_HREF));
          final String pathtoElem=href.getFragment() != null ? href.getFragment() : "String_Node_Str";
          final String old_elementid=pathtoElem.contains(SLASH) ? pathtoElem.substring(0,pathtoElem.indexOf(SLASH)) : pathtoElem;
          if (!old_elementid.isEmpty()) {
            final String new_elementid=currentParsingFileTopicIDChangeTable.get(old_elementid);
            if (new_elementid != null && !new_elementid.isEmpty()) {
              topicref.setAttribute(ATTRIBUTE_NAME_HREF,setFragment(href,new_elementid).toString());
            }
          }
        }
        currentParsingFileTopicIDChangeTable=null;
      }
      currentParsingFile=tempPath;
    }
    if (topicref.hasChildNodes()) {
      final StringWriter tempOutput=(StringWriter)output;
      output=new StringWriter();
      final NodeList children=topicref.getChildNodes();
      for (int i=0; i < children.getLength(); i++) {
        final Node current=children.item(i);
        if (MAP_TOPICREF.matches(current)) {
          processChunk((Element)current,outputFileName);
        }
      }
      final StringBuffer parentResult=tempOutput.getBuffer();
      final CharSequence tmpContent=((StringWriter)output).getBuffer();
      if (parentResult.length() > 0 && parseFilePath != null && !ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(processRoleValue)) {
        insertAfter(hrefValue,parentResult,tmpContent);
      }
 else {
        parentResult.append(tmpContent);
      }
      output=tempOutput;
    }
    if (chunkValue.contains(CHUNK_TO_CONTENT)) {
      final String tmpContent=output.toString();
      writeToContentChunk(tmpContent,outputFileName,needWriteDitaTag);
      output=tempWriter;
      topicID=tempTopicID;
    }
  }
 catch (  final RuntimeException e) {
    throw e;
  }
catch (  final Exception e) {
    logger.error(e.getMessage(),e);
  }
}

Fixed version (ground truth):
private void processChunk(final Element topicref,final URI outputFile){
  final URI hrefValue=toURI(getValue(topicref,ATTRIBUTE_NAME_HREF));
  final Collection<String> chunkValue=split(getValue(topicref,ATTRIBUTE_NAME_CHUNK));
  final URI copytoValue=toURI(getValue(topicref,ATTRIBUTE_NAME_COPY_TO));
  final String scopeValue=getCascadeValue(topicref,ATTRIBUTE_NAME_SCOPE);
  final String classValue=getValue(topicref,ATTRIBUTE_NAME_CLASS);
  final String processRoleValue=getCascadeValue(topicref,ATTRIBUTE_NAME_PROCESSING_ROLE);
  URI outputFileName=outputFile;
  Writer tempWriter=null;
  Set<String> tempTopicID=null;
  targetTopicId=null;
  selectMethod=CHUNK_SELECT_DOCUMENT;
  include=false;
  boolean needWriteDitaTag=true;
  try {
    URI parseFilePath;
    if (copytoValue != null && !chunkValue.contains(CHUNK_TO_CONTENT)) {
      if (hrefValue.getFragment() != null) {
        parseFilePath=setFragment(copytoValue,hrefValue.getFragment());
      }
 else {
        parseFilePath=copytoValue;
      }
    }
 else {
      parseFilePath=hrefValue;
    }
    if (parseFilePath != null && !ATTR_SCOPE_VALUE_EXTERNAL.equals(scopeValue)) {
      if (chunkValue.contains(CHUNK_TO_CONTENT)) {
        tempWriter=output;
        tempTopicID=topicID;
        output=new StringWriter();
        topicID=new HashSet<>();
        if (MAP_MAP.matches(classValue)) {
          outputFileName=currentFile.resolve(parseFilePath);
          needWriteDitaTag=false;
        }
 else         if (copytoValue != null) {
          outputFileName=currentFile.resolve(copytoValue);
        }
 else         if (hrefValue != null) {
          if (chunkValue.contains(CHUNK_SELECT_TOPIC) || chunkValue.contains(CHUNK_SELECT_BRANCH)) {
            if (hrefValue.getFragment() != null) {
              outputFileName=currentFile.resolve(hrefValue.getFragment() + FILE_EXTENSION_DITA);
            }
 else {
              final String firstTopic=getFirstTopicId(new File(stripFragment(currentFile.resolve(hrefValue))));
              if (firstTopic != null) {
                outputFileName=currentFile.resolve(firstTopic + FILE_EXTENSION_DITA);
              }
 else {
                outputFileName=currentFile.resolve(hrefValue);
              }
            }
          }
 else {
            outputFileName=currentFile.resolve(hrefValue);
          }
        }
 else {
          outputFileName=generateOutputFile(currentFile);
        }
        if (new File(outputFileName).exists() && !MAP_MAP.matches(classValue)) {
          final URI t=outputFileName;
          outputFileName=generateOutputFile(currentFile);
          conflictTable.put(outputFileName,t);
        }
        changeTable.put(outputFileName,outputFileName);
        final FileInfo fi=generateFileInfo(outputFileName);
        job.add(fi);
      }
      this.outputFile=outputFileName;
      final URI path=currentFile.resolve(parseFilePath);
      URI newpath;
      if (path.getFragment() != null) {
        newpath=setFragment(outputFileName,path.getFragment());
      }
 else {
        final String firstTopicID=getFirstTopicId(new File(path));
        if (firstTopicID != null) {
          newpath=setFragment(outputFileName,firstTopicID);
        }
 else {
          newpath=outputFileName;
        }
      }
      changeTable.put(path,newpath);
      topicref.setAttribute(ATTRIBUTE_NAME_HREF,getRelativePath(currentFile.resolve(FILE_NAME_STUB_DITAMAP),newpath).toString());
      if (parseFilePath.getFragment() != null) {
        targetTopicId=parseFilePath.getFragment();
      }
      final String s=getChunkByToken(chunkValue,"String_Node_Str",null);
      if (s != null) {
        selectMethod=s;
        if (targetTopicId == null) {
          selectMethod=CHUNK_SELECT_DOCUMENT;
        }
      }
      final URI tempPath=currentParsingFile;
      currentParsingFile=currentFile.resolve(parseFilePath);
      if (!ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(processRoleValue)) {
        currentParsingFileTopicIDChangeTable=new HashMap<>();
        logger.info("String_Node_Str" + currentParsingFile);
        reader.parse(currentParsingFile.toString());
        if (currentParsingFileTopicIDChangeTable.size() > 0) {
          final URI href=toURI(topicref.getAttribute(ATTRIBUTE_NAME_HREF));
          final String pathtoElem=href.getFragment() != null ? href.getFragment() : "String_Node_Str";
          final String old_elementid=pathtoElem.contains(SLASH) ? pathtoElem.substring(0,pathtoElem.indexOf(SLASH)) : pathtoElem;
          if (!old_elementid.isEmpty()) {
            final String new_elementid=currentParsingFileTopicIDChangeTable.get(old_elementid);
            if (new_elementid != null && !new_elementid.isEmpty()) {
              topicref.setAttribute(ATTRIBUTE_NAME_HREF,setFragment(href,new_elementid).toString());
            }
          }
        }
        currentParsingFileTopicIDChangeTable=null;
      }
      currentParsingFile=tempPath;
    }
    if (topicref.hasChildNodes()) {
      final StringWriter tempOutput=(StringWriter)output;
      output=new StringWriter();
      final NodeList children=topicref.getChildNodes();
      for (int i=0; i < children.getLength(); i++) {
        final Node current=children.item(i);
        if (MAP_TOPICREF.matches(current)) {
          processChunk((Element)current,outputFileName);
        }
      }
      final StringBuffer parentResult=tempOutput.getBuffer();
      final CharSequence tmpContent=((StringWriter)output).getBuffer();
      if (parentResult.length() > 0 && parseFilePath != null && !ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(processRoleValue)) {
        insertAfter(hrefValue,parentResult,tmpContent);
      }
 else {
        parentResult.append(tmpContent);
      }
      output=tempOutput;
    }
    if (chunkValue.contains(CHUNK_TO_CONTENT)) {
      final String tmpContent=output.toString();
      writeToContentChunk(tmpContent,outputFileName,needWriteDitaTag);
      output=tempWriter;
      topicID=tempTopicID;
    }
  }
 catch (  final RuntimeException e) {
    throw e;
  }
catch (  final Exception e) {
    logger.error(e.getMessage(),e);
  }
}