Program: 100864
Project: 100864
Buggy source:
private void updateList(LinkedHashMap<String,String> changeTable,Hashtable<String,String> conflictTable,AbstractPipelineInput input){
  DITAOTJavaLogger logger=new DITAOTJavaLogger();
  String tempDir=((PipelineHashIO)input).getAttribute(Constants.ANT_INVOKER_PARAM_TEMPDIR);
  if (!new File(tempDir).isAbsolute()) {
    String baseDir=((PipelineHashIO)input).getAttribute(Constants.ANT_INVOKER_PARAM_BASEDIR);
    tempDir=new File(baseDir,tempDir).getAbsolutePath();
  }
  File ditalist=new File(tempDir,Constants.FILE_NAME_DITA_LIST);
  File xmlDitalist=new File(tempDir,Constants.FILE_NAME_DITA_LIST_XML);
  Properties prop=new Properties();
  try {
    if (xmlDitalist.exists()) {
      prop.loadFromXML(new FileInputStream(xmlDitalist));
    }
 else {
      prop.load(new FileInputStream(ditalist));
    }
  }
 catch (  IOException ex) {
    logger.logException(ex);
  }
  Set<String> hrefTopics=StringUtils.restoreSet((String)prop.getProperty(Constants.HREF_TOPIC_LIST));
  Set<String> chunkTopics=StringUtils.restoreSet((String)prop.getProperty(Constants.CHUNK_TOPIC_LIST));
  for (  String s : chunkTopics) {
    if (!StringUtils.isEmptyString(s) && !s.contains(Constants.SHARP)) {
      Iterator<String> hrefit=hrefTopics.iterator();
      while (hrefit.hasNext()) {
        String ent=hrefit.next();
        if (FileUtils.resolveFile(tempDir,ent).equalsIgnoreCase(FileUtils.resolveFile(tempDir,s))) {
          hrefit.remove();
        }
      }
    }
 else     if (!StringUtils.isEmptyString(s) && hrefTopics.contains(s)) {
      hrefTopics.remove(s);
    }
  }
  Set<String> topicList=new LinkedHashSet<String>(Constants.INT_128);
  Set<String> oldTopicList=StringUtils.restoreSet((String)prop.getProperty(Constants.FULL_DITA_TOPIC_LIST));
  for (  String t : hrefTopics) {
    if (t.lastIndexOf(Constants.SHARP) != -1) {
      t=t.substring(0,t.lastIndexOf(Constants.SHARP));
    }
    if (t.lastIndexOf(Constants.FILE_EXTENSION_DITAMAP) == -1) {
      String ditaext=((PipelineHashIO)input).getAttribute(Constants.ANT_INVOKER_PARAM_DITAEXT);
      t=changeExtName(t,ditaext,ditaext);
    }
    t=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),FileUtils.resolveFile(tempDir,t));
    topicList.add(t);
    if (oldTopicList.contains(t)) {
      oldTopicList.remove(t);
    }
  }
  HashSet<String> chunkedTopicSet=new LinkedHashSet<String>(Constants.INT_128);
  HashSet<String> chunkedDitamapSet=new LinkedHashSet<String>(Constants.INT_128);
  Set<String> ditamapList=StringUtils.restoreSet((String)prop.getProperty(Constants.FULL_DITAMAP_LIST));
  for (  Map.Entry<String,String> entry : changeTable.entrySet()) {
    String oldFile=entry.getKey();
    if (entry.getValue().toString().equals(oldFile)) {
      String newChunkedFile=entry.getValue().toString();
      newChunkedFile=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),newChunkedFile);
      String extName=getExtName(newChunkedFile);
      if (extName != null && !extName.equalsIgnoreCase("String_Node_Str")) {
        chunkedTopicSet.add(newChunkedFile);
        if (!topicList.contains(newChunkedFile)) {
          topicList.add(newChunkedFile);
          if (oldTopicList.contains(newChunkedFile)) {
            oldTopicList.remove(newChunkedFile);
          }
        }
      }
 else {
        if (!ditamapList.contains(newChunkedFile)) {
          ditamapList.add(newChunkedFile);
          if (oldTopicList.contains(newChunkedFile)) {
            oldTopicList.remove(newChunkedFile);
          }
        }
        chunkedDitamapSet.add(newChunkedFile);
      }
    }
  }
  for (  String s : oldTopicList) {
    if (!StringUtils.isEmptyString(s)) {
      File f=new File(tempDir,s);
      if (f.exists()) {
        f.delete();
      }
    }
  }
  for (  Map.Entry<String,String> entry : changeTable.entrySet()) {
    String oldFile=entry.getKey();
    if (entry.getValue().toString().equals(oldFile)) {
      String targetPath=conflictTable.get(entry.getKey());
      if (targetPath != null) {
        File target=new File(targetPath);
        if (!FileUtils.fileExists(target.getAbsolutePath())) {
          File from=new File(entry.getValue().toString());
          String relativePath=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),from.getAbsolutePath());
          target.delete();
          from.renameTo(target);
          if (topicList.contains(relativePath)) {
            topicList.remove(relativePath);
          }
          if (chunkedTopicSet.contains(relativePath)) {
            chunkedTopicSet.remove(relativePath);
          }
          relativePath=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),target.getAbsolutePath());
          topicList.add(relativePath);
          chunkedTopicSet.add(relativePath);
        }
 else {
          conflictTable.remove(entry.getKey());
        }
      }
    }
  }
  Set<String> resourceOnlySet=StringUtils.restoreSet(prop.getProperty(Constants.RESOURCE_ONLY_LIST));
  resourceOnlySet.removeAll(chunkedTopicSet);
  resourceOnlySet.removeAll(chunkedDitamapSet);
  prop.setProperty(Constants.RESOURCE_ONLY_LIST,StringUtils.assembleString(resourceOnlySet,Constants.COMMA));
  prop.setProperty(Constants.FULL_DITA_TOPIC_LIST,StringUtils.assembleString(topicList,Constants.COMMA));
  prop.setProperty(Constants.FULL_DITAMAP_LIST,StringUtils.assembleString(ditamapList,Constants.COMMA));
  topicList.addAll(ditamapList);
  prop.setProperty(Constants.FULL_DITAMAP_TOPIC_LIST,StringUtils.assembleString(topicList,Constants.COMMA));
  try {
    writeList(prop,tempDir,Constants.FULL_DITA_TOPIC_LIST);
    writeList(prop,tempDir,Constants.FULL_DITAMAP_LIST);
    writeList(prop,tempDir,Constants.FULL_DITAMAP_TOPIC_LIST);
  }
 catch (  FileNotFoundException e) {
    logger.logException(e);
  }
catch (  IOException e) {
    logger.logException(e);
  }
  String[] keys={Constants.CHUNKED_DITAMAP_LIST,Constants.CHUNKED_TOPIC_LIST,Constants.RESOURCE_ONLY_LIST};
  List<Set<String>> sets=new ArrayList<Set<String>>();
  sets.add(chunkedDitamapSet);
  sets.add(chunkedTopicSet);
  sets.add(resourceOnlySet);
  for (int i=0; i < keys.length; i++) {
    String key=keys[i];
    String fileKey=key.substring(0,key.lastIndexOf("String_Node_Str")) + "String_Node_Str";
    prop.put(fileKey,key.substring(0,key.lastIndexOf("String_Node_Str")) + "String_Node_Str");
    File list=new File(tempDir,prop.getProperty(fileKey));
    BufferedWriter bufferedWriter=null;
    try {
      bufferedWriter=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
      Iterator<String> it=sets.get(i).iterator();
      while (it.hasNext()) {
        bufferedWriter.write(it.next());
        if (it.hasNext()) {
          bufferedWriter.write("String_Node_Str");
        }
      }
      bufferedWriter.flush();
      bufferedWriter.close();
    }
 catch (    FileNotFoundException e) {
      e.printStackTrace();
    }
catch (    IOException e) {
      e.printStackTrace();
    }
 finally {
      if (bufferedWriter != null) {
        try {
          bufferedWriter.close();
        }
 catch (        IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
  addSetToProperties(prop,Constants.CHUNKED_DITAMAP_LIST,chunkedDitamapSet);
  addSetToProperties(prop,Constants.CHUNKED_TOPIC_LIST,chunkedTopicSet);
  Content content=new ContentImpl();
  content.setValue(prop);
  PropertiesWriter writer=new PropertiesWriter();
  writer.setContent(content);
  try {
    writer.write(ditalist.getAbsolutePath());
    writer.writeToXML(xmlDitalist.getAbsolutePath());
  }
 catch (  DITAOTException ex) {
    logger.logException(ex);
  }
}

Fixed version (ground truth):
private void updateList(LinkedHashMap<String,String> changeTable,Hashtable<String,String> conflictTable,AbstractPipelineInput input){
  DITAOTJavaLogger logger=new DITAOTJavaLogger();
  String tempDir=((PipelineHashIO)input).getAttribute(Constants.ANT_INVOKER_PARAM_TEMPDIR);
  if (!new File(tempDir).isAbsolute()) {
    String baseDir=((PipelineHashIO)input).getAttribute(Constants.ANT_INVOKER_PARAM_BASEDIR);
    tempDir=new File(baseDir,tempDir).getAbsolutePath();
  }
  File ditalist=new File(tempDir,Constants.FILE_NAME_DITA_LIST);
  File xmlDitalist=new File(tempDir,Constants.FILE_NAME_DITA_LIST_XML);
  Properties prop=new Properties();
  InputStream in=null;
  try {
    if (xmlDitalist.exists()) {
      in=new FileInputStream(xmlDitalist);
      prop.loadFromXML(in);
    }
 else {
      in=new FileInputStream(ditalist);
      prop.load(in);
    }
  }
 catch (  IOException ex) {
    logger.logException(ex);
  }
 finally {
    if (in != null) {
      try {
        in.close();
      }
 catch (      IOException e) {
        logger.logException(e);
      }
    }
  }
  Set<String> hrefTopics=StringUtils.restoreSet((String)prop.getProperty(Constants.HREF_TOPIC_LIST));
  Set<String> chunkTopics=StringUtils.restoreSet((String)prop.getProperty(Constants.CHUNK_TOPIC_LIST));
  for (  String s : chunkTopics) {
    if (!StringUtils.isEmptyString(s) && !s.contains(Constants.SHARP)) {
      Iterator<String> hrefit=hrefTopics.iterator();
      while (hrefit.hasNext()) {
        String ent=hrefit.next();
        if (FileUtils.resolveFile(tempDir,ent).equalsIgnoreCase(FileUtils.resolveFile(tempDir,s))) {
          hrefit.remove();
        }
      }
    }
 else     if (!StringUtils.isEmptyString(s) && hrefTopics.contains(s)) {
      hrefTopics.remove(s);
    }
  }
  Set<String> topicList=new LinkedHashSet<String>(Constants.INT_128);
  Set<String> oldTopicList=StringUtils.restoreSet((String)prop.getProperty(Constants.FULL_DITA_TOPIC_LIST));
  for (  String t : hrefTopics) {
    if (t.lastIndexOf(Constants.SHARP) != -1) {
      t=t.substring(0,t.lastIndexOf(Constants.SHARP));
    }
    if (t.lastIndexOf(Constants.FILE_EXTENSION_DITAMAP) == -1) {
      String ditaext=((PipelineHashIO)input).getAttribute(Constants.ANT_INVOKER_PARAM_DITAEXT);
      t=changeExtName(t,ditaext,ditaext);
    }
    t=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),FileUtils.resolveFile(tempDir,t));
    topicList.add(t);
    if (oldTopicList.contains(t)) {
      oldTopicList.remove(t);
    }
  }
  HashSet<String> chunkedTopicSet=new LinkedHashSet<String>(Constants.INT_128);
  HashSet<String> chunkedDitamapSet=new LinkedHashSet<String>(Constants.INT_128);
  Set<String> ditamapList=StringUtils.restoreSet((String)prop.getProperty(Constants.FULL_DITAMAP_LIST));
  for (  Map.Entry<String,String> entry : changeTable.entrySet()) {
    String oldFile=entry.getKey();
    if (entry.getValue().equals(oldFile)) {
      String newChunkedFile=entry.getValue();
      newChunkedFile=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),newChunkedFile);
      String extName=getExtName(newChunkedFile);
      if (extName != null && !extName.equalsIgnoreCase("String_Node_Str")) {
        chunkedTopicSet.add(newChunkedFile);
        if (!topicList.contains(newChunkedFile)) {
          topicList.add(newChunkedFile);
          if (oldTopicList.contains(newChunkedFile)) {
            oldTopicList.remove(newChunkedFile);
          }
        }
      }
 else {
        if (!ditamapList.contains(newChunkedFile)) {
          ditamapList.add(newChunkedFile);
          if (oldTopicList.contains(newChunkedFile)) {
            oldTopicList.remove(newChunkedFile);
          }
        }
        chunkedDitamapSet.add(newChunkedFile);
      }
    }
  }
  for (  String s : oldTopicList) {
    if (!StringUtils.isEmptyString(s)) {
      File f=new File(tempDir,s);
      if (f.exists()) {
        f.delete();
      }
    }
  }
  for (  Map.Entry<String,String> entry : changeTable.entrySet()) {
    String oldFile=entry.getKey();
    if (entry.getValue().equals(oldFile)) {
      String targetPath=conflictTable.get(entry.getKey());
      if (targetPath != null) {
        File target=new File(targetPath);
        if (!FileUtils.fileExists(target.getAbsolutePath())) {
          File from=new File(entry.getValue());
          String relativePath=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),from.getAbsolutePath());
          target.delete();
          from.renameTo(target);
          if (topicList.contains(relativePath)) {
            topicList.remove(relativePath);
          }
          if (chunkedTopicSet.contains(relativePath)) {
            chunkedTopicSet.remove(relativePath);
          }
          relativePath=FileUtils.getRelativePathFromMap(xmlDitalist.getAbsolutePath(),target.getAbsolutePath());
          topicList.add(relativePath);
          chunkedTopicSet.add(relativePath);
        }
 else {
          conflictTable.remove(entry.getKey());
        }
      }
    }
  }
  Set<String> resourceOnlySet=StringUtils.restoreSet(prop.getProperty(Constants.RESOURCE_ONLY_LIST));
  resourceOnlySet.removeAll(chunkedTopicSet);
  resourceOnlySet.removeAll(chunkedDitamapSet);
  prop.setProperty(Constants.RESOURCE_ONLY_LIST,StringUtils.assembleString(resourceOnlySet,Constants.COMMA));
  prop.setProperty(Constants.FULL_DITA_TOPIC_LIST,StringUtils.assembleString(topicList,Constants.COMMA));
  prop.setProperty(Constants.FULL_DITAMAP_LIST,StringUtils.assembleString(ditamapList,Constants.COMMA));
  topicList.addAll(ditamapList);
  prop.setProperty(Constants.FULL_DITAMAP_TOPIC_LIST,StringUtils.assembleString(topicList,Constants.COMMA));
  try {
    writeList(prop,tempDir,Constants.FULL_DITA_TOPIC_LIST);
    writeList(prop,tempDir,Constants.FULL_DITAMAP_LIST);
    writeList(prop,tempDir,Constants.FULL_DITAMAP_TOPIC_LIST);
  }
 catch (  FileNotFoundException e) {
    logger.logException(e);
  }
catch (  IOException e) {
    logger.logException(e);
  }
  String[] keys={Constants.CHUNKED_DITAMAP_LIST,Constants.CHUNKED_TOPIC_LIST,Constants.RESOURCE_ONLY_LIST};
  List<Set<String>> sets=new ArrayList<Set<String>>();
  sets.add(chunkedDitamapSet);
  sets.add(chunkedTopicSet);
  sets.add(resourceOnlySet);
  for (int i=0; i < keys.length; i++) {
    String key=keys[i];
    String fileKey=key.substring(0,key.lastIndexOf("String_Node_Str")) + "String_Node_Str";
    prop.put(fileKey,key.substring(0,key.lastIndexOf("String_Node_Str")) + "String_Node_Str");
    File list=new File(tempDir,prop.getProperty(fileKey));
    BufferedWriter bufferedWriter=null;
    try {
      bufferedWriter=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
      Iterator<String> it=sets.get(i).iterator();
      while (it.hasNext()) {
        bufferedWriter.write(it.next());
        if (it.hasNext()) {
          bufferedWriter.write("String_Node_Str");
        }
      }
      bufferedWriter.flush();
      bufferedWriter.close();
    }
 catch (    FileNotFoundException e) {
      e.printStackTrace();
    }
catch (    IOException e) {
      e.printStackTrace();
    }
 finally {
      if (bufferedWriter != null) {
        try {
          bufferedWriter.close();
        }
 catch (        IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
  addSetToProperties(prop,Constants.CHUNKED_DITAMAP_LIST,chunkedDitamapSet);
  addSetToProperties(prop,Constants.CHUNKED_TOPIC_LIST,chunkedTopicSet);
  Content content=new ContentImpl();
  content.setValue(prop);
  PropertiesWriter writer=new PropertiesWriter();
  writer.setContent(content);
  try {
    writer.write(ditalist.getAbsolutePath());
    writer.writeToXML(xmlDitalist.getAbsolutePath());
  }
 catch (  DITAOTException ex) {
    logger.logException(ex);
  }
}