Program: 100610
Project: 100610
Buggy source:
@Override public void write(final URI currentFile) throws DITAOTException {
  this.currentFile=currentFile;
  final URI hrefValue=toURI(getValue(rootTopicref,ATTRIBUTE_NAME_HREF));
  final URI copytoValue=toURI(getValue(rootTopicref,ATTRIBUTE_NAME_COPY_TO));
  final String scopeValue=getCascadeValue(rootTopicref,ATTRIBUTE_NAME_SCOPE);
  URI parseFilePath;
  final Collection<String> chunkValue=split(getValue(rootTopicref,ATTRIBUTE_NAME_CHUNK));
  final String processRoleValue=getCascadeValue(rootTopicref,ATTRIBUTE_NAME_PROCESSING_ROLE);
  boolean dotchunk=false;
  if (copytoValue != null) {
    if (hrefValue != null && hrefValue.getFragment() != null) {
      parseFilePath=setFragment(copytoValue,hrefValue.getFragment());
    }
 else {
      parseFilePath=copytoValue;
    }
  }
 else {
    parseFilePath=hrefValue;
  }
  try {
    currentParsingFile=currentFile.resolve(parseFilePath);
    URI outputFileName;
    String id=null;
    String firstTopicID=null;
    if (parseFilePath.getFragment() != null) {
      id=parseFilePath.getFragment();
      if (chunkValue.contains(CHUNK_SELECT_BRANCH)) {
        outputFileName=resolve(currentFile,id + FILE_EXTENSION_DITA);
        targetTopicId=id;
        startFromFirstTopic=false;
        selectMethod=CHUNK_SELECT_BRANCH;
      }
 else       if (chunkValue.contains(CHUNK_SELECT_DOCUMENT)) {
        firstTopicID=getFirstTopicId(currentFile.resolve(parseFilePath).getPath());
        topicDoc=getTopicDoc(currentFile.resolve(parseFilePath));
        if (firstTopicID != null) {
          outputFileName=resolve(currentFile,firstTopicID + FILE_EXTENSION_DITA);
          targetTopicId=firstTopicID;
        }
 else {
          outputFileName=resolve(currentParsingFile,null);
          dotchunk=true;
          targetTopicId=null;
        }
        selectMethod=CHUNK_SELECT_DOCUMENT;
      }
 else {
        outputFileName=resolve(currentFile,id + FILE_EXTENSION_DITA);
        targetTopicId=id;
        startFromFirstTopic=false;
        selectMethod=CHUNK_SELECT_TOPIC;
      }
    }
 else {
      firstTopicID=getFirstTopicId(currentFile.resolve(parseFilePath).getPath());
      topicDoc=getTopicDoc(currentFile.resolve(parseFilePath));
      if (firstTopicID != null) {
        outputFileName=resolve(currentFile,firstTopicID + FILE_EXTENSION_DITA);
        targetTopicId=firstTopicID;
      }
 else {
        outputFileName=resolve(currentParsingFile,null);
        dotchunk=true;
        targetTopicId=null;
      }
      selectMethod=CHUNK_SELECT_DOCUMENT;
    }
    if (copytoValue != null) {
      outputFileName=resolve(currentFile,copytoValue.toString());
    }
    if (new File(outputFileName).exists()) {
      final URI t=outputFileName;
      outputFileName=resolve(currentFile,generateFilename());
      conflictTable.put(outputFileName,t);
      dotchunk=false;
    }
    output=new OutputStreamWriter(new FileOutputStream(new File(outputFileName)),UTF8);
    outputFile=outputFileName;
    if (!dotchunk) {
      final FileInfo fi=generateFileInfo(outputFile);
      job.add(fi);
      changeTable.put(currentFile.resolve(parseFilePath),setFragment(outputFileName,id));
      changeTable.put(outputFileName,outputFileName);
    }
    final URI newHref=setFragment(getRelativePath(currentFile.resolve(FILE_NAME_STUB_DITAMAP),outputFileName),firstTopicID != null ? firstTopicID : id);
    rootTopicref.setAttribute(ATTRIBUTE_NAME_HREF,newHref.toString());
    include=false;
    addStubElements();
    if (rootTopicref.getNextSibling() != null) {
      rootTopicref.getParentNode().insertBefore(siblingStub,rootTopicref.getNextSibling());
    }
 else {
      rootTopicref.getParentNode().appendChild(siblingStub);
    }
    reader.setErrorHandler(new DITAOTXMLErrorHandler(currentParsingFile.getPath(),logger));
    logger.info("String_Node_Str" + currentParsingFile);
    reader.parse(currentParsingFile.toString());
    output.flush();
    removeStubElements();
  }
 catch (  final RuntimeException e) {
    throw e;
  }
catch (  final Exception e) {
    logger.error(e.getMessage(),e);
  }
 finally {
    try {
      if (output != null) {
        output.close();
        output=null;
        if (dotchunk) {
          final File dst=new File(currentParsingFile);
          final File src=new File(outputFile);
          logger.debug("String_Node_Str" + currentParsingFile);
          deleteQuietly(dst);
          logger.debug("String_Node_Str" + outputFile + "String_Node_Str"+ currentParsingFile);
          moveFile(src,dst);
          final FileInfo fi=job.getFileInfo(outputFile);
          if (fi != null) {
            job.remove(fi);
          }
        }
      }
    }
 catch (    final Exception ex) {
      logger.error(ex.getMessage(),ex);
    }
  }
}

Fixed version (ground truth):
@Override public void write(final URI currentFile) throws DITAOTException {
  this.currentFile=currentFile;
  final URI hrefValue=toURI(getValue(rootTopicref,ATTRIBUTE_NAME_HREF));
  final URI copytoValue=toURI(getValue(rootTopicref,ATTRIBUTE_NAME_COPY_TO));
  final String scopeValue=getCascadeValue(rootTopicref,ATTRIBUTE_NAME_SCOPE);
  URI parseFilePath;
  final Collection<String> chunkValue=split(getValue(rootTopicref,ATTRIBUTE_NAME_CHUNK));
  final String processRoleValue=getCascadeValue(rootTopicref,ATTRIBUTE_NAME_PROCESSING_ROLE);
  boolean dotchunk=false;
  if (copytoValue != null) {
    if (hrefValue != null && hrefValue.getFragment() != null) {
      parseFilePath=setFragment(copytoValue,hrefValue.getFragment());
    }
 else {
      parseFilePath=copytoValue;
    }
  }
 else {
    parseFilePath=hrefValue;
  }
  try {
    currentParsingFile=currentFile.resolve(parseFilePath);
    URI outputFileName;
    String id=null;
    String firstTopicID=null;
    if (parseFilePath.getFragment() != null) {
      id=parseFilePath.getFragment();
      if (chunkValue.contains(CHUNK_SELECT_BRANCH)) {
        outputFileName=resolve(currentFile,id + FILE_EXTENSION_DITA);
        targetTopicId=id;
        startFromFirstTopic=false;
        selectMethod=CHUNK_SELECT_BRANCH;
      }
 else       if (chunkValue.contains(CHUNK_SELECT_DOCUMENT)) {
        firstTopicID=getFirstTopicId(new File(stripFragment(currentFile.resolve(parseFilePath))));
        topicDoc=getTopicDoc(currentFile.resolve(parseFilePath));
        if (firstTopicID != null) {
          outputFileName=resolve(currentFile,firstTopicID + FILE_EXTENSION_DITA);
          targetTopicId=firstTopicID;
        }
 else {
          outputFileName=resolve(currentParsingFile,null);
          dotchunk=true;
          targetTopicId=null;
        }
        selectMethod=CHUNK_SELECT_DOCUMENT;
      }
 else {
        outputFileName=resolve(currentFile,id + FILE_EXTENSION_DITA);
        targetTopicId=id;
        startFromFirstTopic=false;
        selectMethod=CHUNK_SELECT_TOPIC;
      }
    }
 else {
      firstTopicID=getFirstTopicId(new File(stripFragment(currentFile.resolve(parseFilePath))));
      topicDoc=getTopicDoc(currentFile.resolve(parseFilePath));
      if (firstTopicID != null) {
        outputFileName=resolve(currentFile,firstTopicID + FILE_EXTENSION_DITA);
        targetTopicId=firstTopicID;
      }
 else {
        outputFileName=resolve(currentParsingFile,null);
        dotchunk=true;
        targetTopicId=null;
      }
      selectMethod=CHUNK_SELECT_DOCUMENT;
    }
    if (copytoValue != null) {
      outputFileName=resolve(currentFile,copytoValue.toString());
    }
    if (new File(outputFileName).exists()) {
      final URI t=outputFileName;
      outputFileName=resolve(currentFile,generateFilename());
      conflictTable.put(outputFileName,t);
      dotchunk=false;
    }
    output=new OutputStreamWriter(new FileOutputStream(new File(outputFileName)),UTF8);
    outputFile=outputFileName;
    if (!dotchunk) {
      final FileInfo fi=generateFileInfo(outputFile);
      job.add(fi);
      changeTable.put(currentFile.resolve(parseFilePath),setFragment(outputFileName,id));
      changeTable.put(outputFileName,outputFileName);
    }
    final URI newHref=setFragment(getRelativePath(currentFile.resolve(FILE_NAME_STUB_DITAMAP),outputFileName),firstTopicID != null ? firstTopicID : id);
    rootTopicref.setAttribute(ATTRIBUTE_NAME_HREF,newHref.toString());
    include=false;
    addStubElements();
    if (rootTopicref.getNextSibling() != null) {
      rootTopicref.getParentNode().insertBefore(siblingStub,rootTopicref.getNextSibling());
    }
 else {
      rootTopicref.getParentNode().appendChild(siblingStub);
    }
    reader.setErrorHandler(new DITAOTXMLErrorHandler(currentParsingFile.getPath(),logger));
    logger.info("String_Node_Str" + currentParsingFile);
    reader.parse(currentParsingFile.toString());
    output.flush();
    removeStubElements();
  }
 catch (  final RuntimeException e) {
    throw e;
  }
catch (  final Exception e) {
    logger.error(e.getMessage(),e);
  }
 finally {
    try {
      if (output != null) {
        output.close();
        output=null;
        if (dotchunk) {
          final File dst=new File(currentParsingFile);
          final File src=new File(outputFile);
          logger.debug("String_Node_Str" + currentParsingFile);
          deleteQuietly(dst);
          logger.debug("String_Node_Str" + outputFile + "String_Node_Str"+ currentParsingFile);
          moveFile(src,dst);
          final FileInfo fi=job.getFileInfo(outputFile);
          if (fi != null) {
            job.remove(fi);
          }
        }
      }
    }
 catch (    final Exception ex) {
      logger.error(ex.getMessage(),ex);
    }
  }
}