Program: 69220
Project: 69220
Buggy source:
@Override public void close() throws IOException {
  if (!to_add.isEmpty() || !to_rename.isEmpty() || !to_delete.isEmpty()|| !to_duplicate.isEmpty()) {
    IOutCreateCallback<IOutItemAllFormats> callback=new IOutCreateCallback<IOutItemAllFormats>(){
      HashMap<Integer,String> idx_to_delete=new HashMap<>();
      HashMap<Integer,String> idx_to_rename=new HashMap<>();
      ArrayList<Object[]> idx_to_duplicate=new ArrayList<>();
      int old_idx=0, old_tot=0;
      HashMap<Integer,RandomAccessFile> rafs=new HashMap<>();
      HashMap<Integer,File> tmpfiles=new HashMap<>();
      int curr_index=-1;
{
        if (iinarchive != null) {
          old_tot=iinarchive.getNumberOfItems();
          for (int i=0; i < old_tot; i++) {
            String path=iinarchive.getProperty(i,PropID.PATH).toString();
            for (            String to_d : to_delete) {
              if (path.equals(to_d)) {
                idx_to_delete.put(i,to_d);
                break;
              }
            }
            for (            Entry<String,String> to_r : to_rename.entrySet()) {
              if (path.equals(to_r.getKey())) {
                idx_to_rename.put(i,to_r.getValue());
                break;
              }
            }
            for (            Entry<String,String> to_p : to_duplicate.entrySet()) {
              if (path.equals(to_p.getValue())) {
                idx_to_duplicate.add(new Object[]{i,to_p.getKey(),null});
              }
            }
          }
          if (to_delete.size() != idx_to_delete.size())           System.err.println("String_Node_Str" + to_delete.size() + "String_Node_Str"+ idx_to_delete.size());
          if (to_rename.size() != idx_to_rename.size())           System.err.println("String_Node_Str" + to_rename.size() + "String_Node_Str"+ idx_to_rename.size());
          if (to_duplicate.size() != idx_to_duplicate.size())           System.err.println("String_Node_Str" + to_duplicate.size() + "String_Node_Str"+ idx_to_duplicate.size());
        }
      }
      @Override public void setTotal(      long total) throws SevenZipException {
      }
      @Override public void setCompleted(      long complete) throws SevenZipException {
      }
      @Override public void setOperationResult(      boolean operationResultOk) throws SevenZipException {
        try {
          if (curr_index >= 0) {
            if (rafs.containsKey(curr_index))             rafs.remove(curr_index).close();
            if (tmpfiles.containsKey(curr_index))             tmpfiles.remove(curr_index).delete();
            curr_index=-1;
          }
        }
 catch (        IOException e) {
          e.printStackTrace();
        }
      }
      @Override public ISequentialInStream getStream(      int index) throws SevenZipException {
        curr_index=index;
        if (index + idx_to_delete.size() - old_tot < to_add.size()) {
          try {
            rafs.put(index,new RandomAccessFile(new File(getTempDir(),to_add.get(index + idx_to_delete.size() - old_tot)),"String_Node_Str"));
            return new RandomAccessFileInStream(rafs.get(index));
          }
 catch (          FileNotFoundException e) {
            e.printStackTrace();
          }
catch (          IOException e) {
            e.printStackTrace();
          }
        }
        if (index + idx_to_delete.size() - old_tot - to_add.size() < to_duplicate.size()) {
          try {
            if (!rafs.containsKey(index)) {
              HashMap<Integer,File> tmpfiles_by_oldindex=new HashMap<>();
              HashMap<Integer,RandomAccessFile> rafs2=new HashMap<>();
              for (              Object[] o : idx_to_duplicate) {
                if (!tmpfiles_by_oldindex.containsKey(o[0]))                 tmpfiles_by_oldindex.put((Integer)o[0],Files.createTempFile("String_Node_Str",null).toFile());
                tmpfiles.put((Integer)o[2],tmpfiles_by_oldindex.get(o[0]));
              }
              for (              Entry<Integer,File> entry : tmpfiles_by_oldindex.entrySet())               rafs2.put(entry.getKey(),new RandomAccessFile(entry.getValue(),"String_Node_Str"));
              int[] indices=idx_to_duplicate.stream().flatMapToInt(objs -> IntStream.of((Integer)objs[0])).toArray();
              iinarchive.extract(indices,false,new IArchiveExtractCallback(){
                @Override public void setTotal(                long total) throws SevenZipException {
                }
                @Override public void setCompleted(                long complete) throws SevenZipException {
                }
                @Override public void setOperationResult(                ExtractOperationResult extractOperationResult) throws SevenZipException {
                }
                @Override public void prepareOperation(                ExtractAskMode extractAskMode) throws SevenZipException {
                }
                @Override public ISequentialOutStream getStream(                int idx,                ExtractAskMode extractAskMode) throws SevenZipException {
                  if (ExtractAskMode.EXTRACT == extractAskMode)                   return new RandomAccessFileOutStream(rafs2.get(idx));
                  return null;
                }
              }
);
              for (              RandomAccessFile raf2 : rafs2.values())               raf2.close();
              for (              Entry<Integer,File> entry : tmpfiles.entrySet())               rafs.put(entry.getKey(),new RandomAccessFile(entry.getValue(),"String_Node_Str"));
            }
            rafs.get(index).seek(0);
            return new RandomAccessFileInStream(rafs.get(index));
          }
 catch (          IOException e) {
            e.printStackTrace();
          }
        }
        return null;
      }
      @Override public IOutItemAllFormats getItemInformation(      int index,      OutItemFactory<IOutItemAllFormats> outItemFactory) throws SevenZipException {
        try {
          while (idx_to_delete.containsKey(old_idx))           old_idx++;
          if (idx_to_rename.containsKey(old_idx)) {
            IOutItemAllFormats item=outItemFactory.createOutItemAndCloneProperties(old_idx);
            item.setPropertyPath(idx_to_rename.get(old_idx));
            return item;
          }
          if (old_idx < old_tot)           return outItemFactory.createOutItem(old_idx);
 else {
            if (old_idx - old_tot < to_add.size()) {
              String file=to_add.get(old_idx - old_tot);
              IOutItemAllFormats item=outItemFactory.createOutItem();
              item.setPropertyPath(file);
              try {
                item.setDataSize(new File(getTempDir(),file).length());
              }
 catch (              IOException e) {
                e.printStackTrace();
              }
              item.setUpdateIsNewData(true);
              item.setUpdateIsNewProperties(true);
              return item;
            }
 else {
              Object[] objects=idx_to_duplicate.get(old_idx - old_tot - to_add.size());
              ISimpleInArchiveItem ref_item=iinarchive.getSimpleInterface().getArchiveItem((Integer)objects[0]);
              objects[2]=index;
              IOutItemAllFormats item=outItemFactory.createOutItem();
              item.setPropertyPath((String)objects[1]);
              item.setDataSize(ref_item.getSize());
              item.setUpdateIsNewData(true);
              item.setUpdateIsNewProperties(true);
              return item;
            }
          }
        }
  finally {
          old_idx++;
        }
      }
    }
;
    if (archive.exists() && iinarchive != null) {
      File tmpfile=Files.createTempFile(archive.getParentFile().toPath(),"String_Node_Str","String_Node_Str" + ext).toFile();
      tmpfile.delete();
      try (RandomAccessFile raf=new RandomAccessFile(tmpfile,"String_Node_Str")){
        IOutUpdateArchive<IOutItemAllFormats> iout=iinarchive.getConnectedOutArchive();
        SetOptions(iout);
        int itemsCount=iinarchive.getNumberOfItems() - to_delete.size() + to_add.size() + to_duplicate.size();
        iout.updateItems(new RandomAccessFileOutStream(raf),itemsCount,callback);
      }
       for (      Closeable c : closeables)       c.close();
      closeables.clear();
      if (tmpfile.exists() && tmpfile.length() > 0) {
        archive.delete();
        if (!tmpfile.renameTo(archive))         tmpfile.delete();
      }
    }
 else {
      try (IOutCreateArchive<IOutItemAllFormats> iout=SevenZip.openOutArchive(format);RandomAccessFile raf=new RandomAccessFile(archive,"String_Node_Str")){
        SetOptions(iout);
        int itemsCount=to_add.size() + to_duplicate.size();
        iout.createArchive(new RandomAccessFileOutStream(raf),itemsCount,callback);
      }
       for (      Closeable c : closeables)       c.close();
      closeables.clear();
    }
  }
 else {
    for (    Closeable c : closeables)     c.close();
    closeables.clear();
  }
  try {
    if (tempDir != null)     FileUtils.deleteDirectory(tempDir);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  if (!to_add.isEmpty() || !to_rename.isEmpty() || !to_delete.isEmpty()|| !to_duplicate.isEmpty()) {
    HashMap<Integer,RandomAccessFile> rafs=new HashMap<>();
    HashMap<Integer,File> tmpfiles=new HashMap<>();
    IOutCreateCallback<IOutItemAllFormats> callback=new IOutCreateCallback<IOutItemAllFormats>(){
      HashMap<Integer,String> idx_to_delete=new HashMap<>();
      HashMap<Integer,String> idx_to_rename=new HashMap<>();
      ArrayList<Object[]> idx_to_duplicate=new ArrayList<>();
      int old_idx=0, old_tot=0;
      int curr_index=-1;
{
        if (iinarchive != null) {
          old_tot=iinarchive.getNumberOfItems();
          for (int i=0; i < old_tot; i++) {
            String path=iinarchive.getProperty(i,PropID.PATH).toString();
            for (            String to_d : to_delete) {
              if (path.equals(to_d)) {
                idx_to_delete.put(i,to_d);
                break;
              }
            }
            for (            Entry<String,String> to_r : to_rename.entrySet()) {
              if (path.equals(to_r.getKey())) {
                idx_to_rename.put(i,to_r.getValue());
                break;
              }
            }
            for (            Entry<String,String> to_p : to_duplicate.entrySet()) {
              if (path.equals(to_p.getValue())) {
                idx_to_duplicate.add(new Object[]{i,to_p.getKey(),null});
              }
            }
          }
          if (to_delete.size() != idx_to_delete.size())           System.err.println("String_Node_Str" + to_delete.size() + "String_Node_Str"+ idx_to_delete.size());
          if (to_rename.size() != idx_to_rename.size())           System.err.println("String_Node_Str" + to_rename.size() + "String_Node_Str"+ idx_to_rename.size());
          if (to_duplicate.size() != idx_to_duplicate.size())           System.err.println("String_Node_Str" + to_duplicate.size() + "String_Node_Str"+ idx_to_duplicate.size());
        }
      }
      @Override public void setTotal(      long total) throws SevenZipException {
      }
      @Override public void setCompleted(      long complete) throws SevenZipException {
      }
      @Override public void setOperationResult(      boolean operationResultOk) throws SevenZipException {
      }
      @Override public ISequentialInStream getStream(      int index) throws SevenZipException {
        System.out.println("String_Node_Str" + index);
        curr_index=index;
        if (index + idx_to_delete.size() - old_tot < to_add.size()) {
          try {
            System.out.println("String_Node_Str" + new File(getTempDir(),to_add.get(index + idx_to_delete.size() - old_tot)));
            rafs.put(index,new RandomAccessFile(new File(getTempDir(),to_add.get(index + idx_to_delete.size() - old_tot)),"String_Node_Str"));
            return new RandomAccessFileInStream(rafs.get(index));
          }
 catch (          FileNotFoundException e) {
            e.printStackTrace();
          }
catch (          IOException e) {
            e.printStackTrace();
          }
        }
        if (index + idx_to_delete.size() - old_tot - to_add.size() < to_duplicate.size()) {
          try {
            if (!rafs.containsKey(index)) {
              HashMap<Integer,File> tmpfiles_by_oldindex=new HashMap<>();
              HashMap<Integer,RandomAccessFile> rafs2=new HashMap<>();
              for (              Object[] o : idx_to_duplicate) {
                if (!tmpfiles_by_oldindex.containsKey(o[0]))                 tmpfiles_by_oldindex.put((Integer)o[0],Files.createTempFile("String_Node_Str",null).toFile());
                tmpfiles.put((Integer)o[2],tmpfiles_by_oldindex.get(o[0]));
              }
              for (              Entry<Integer,File> entry : tmpfiles_by_oldindex.entrySet())               rafs2.put(entry.getKey(),new RandomAccessFile(entry.getValue(),"String_Node_Str"));
              int[] indices=idx_to_duplicate.stream().flatMapToInt(objs -> IntStream.of((Integer)objs[0])).toArray();
              iinarchive.extract(indices,false,new IArchiveExtractCallback(){
                @Override public void setTotal(                long total) throws SevenZipException {
                }
                @Override public void setCompleted(                long complete) throws SevenZipException {
                }
                @Override public void setOperationResult(                ExtractOperationResult extractOperationResult) throws SevenZipException {
                }
                @Override public void prepareOperation(                ExtractAskMode extractAskMode) throws SevenZipException {
                }
                @Override public ISequentialOutStream getStream(                int idx,                ExtractAskMode extractAskMode) throws SevenZipException {
                  if (ExtractAskMode.EXTRACT == extractAskMode)                   return new RandomAccessFileOutStream(rafs2.get(idx));
                  return null;
                }
              }
);
              for (              RandomAccessFile raf2 : rafs2.values())               raf2.close();
              for (              Entry<Integer,File> entry : tmpfiles.entrySet())               rafs.put(entry.getKey(),new RandomAccessFile(entry.getValue(),"String_Node_Str"));
            }
            rafs.get(index).seek(0);
            return new RandomAccessFileInStream(rafs.get(index));
          }
 catch (          IOException e) {
            e.printStackTrace();
          }
        }
        return null;
      }
      @Override public IOutItemAllFormats getItemInformation(      int index,      OutItemFactory<IOutItemAllFormats> outItemFactory) throws SevenZipException {
        try {
          while (idx_to_delete.containsKey(old_idx))           old_idx++;
          if (idx_to_rename.containsKey(old_idx)) {
            IOutItemAllFormats item=outItemFactory.createOutItemAndCloneProperties(old_idx);
            item.setPropertyPath(idx_to_rename.get(old_idx));
            return item;
          }
          if (old_idx < old_tot)           return outItemFactory.createOutItem(old_idx);
 else {
            if (old_idx - old_tot < to_add.size()) {
              String file=to_add.get(old_idx - old_tot);
              IOutItemAllFormats item=outItemFactory.createOutItem();
              item.setPropertyPath(file);
              try {
                item.setDataSize(new File(getTempDir(),file).length());
              }
 catch (              IOException e) {
                e.printStackTrace();
              }
              item.setUpdateIsNewData(true);
              item.setUpdateIsNewProperties(true);
              return item;
            }
 else {
              Object[] objects=idx_to_duplicate.get(old_idx - old_tot - to_add.size());
              ISimpleInArchiveItem ref_item=iinarchive.getSimpleInterface().getArchiveItem((Integer)objects[0]);
              objects[2]=index;
              IOutItemAllFormats item=outItemFactory.createOutItem();
              item.setPropertyPath((String)objects[1]);
              item.setDataSize(ref_item.getSize());
              item.setUpdateIsNewData(true);
              item.setUpdateIsNewProperties(true);
              return item;
            }
          }
        }
  finally {
          old_idx++;
        }
      }
    }
;
    if (archive.exists() && iinarchive != null) {
      File tmpfile=Files.createTempFile(archive.getParentFile().toPath(),"String_Node_Str","String_Node_Str" + ext).toFile();
      tmpfile.delete();
      try (RandomAccessFile raf=new RandomAccessFile(tmpfile,"String_Node_Str")){
        IOutUpdateArchive<IOutItemAllFormats> iout=iinarchive.getConnectedOutArchive();
        SetOptions(iout);
        int itemsCount=iinarchive.getNumberOfItems() - to_delete.size() + to_add.size() + to_duplicate.size();
        iout.updateItems(new RandomAccessFileOutStream(raf),itemsCount,callback);
      }
       for (      Closeable c : closeables)       c.close();
      closeables.clear();
      if (tmpfile.exists() && tmpfile.length() > 0) {
        archive.delete();
        if (!tmpfile.renameTo(archive))         tmpfile.delete();
      }
    }
 else {
      try (IOutCreateArchive<IOutItemAllFormats> iout=SevenZip.openOutArchive(format);RandomAccessFile raf=new RandomAccessFile(archive,"String_Node_Str")){
        SetOptions(iout);
        int itemsCount=to_add.size() + to_duplicate.size();
        iout.createArchive(new RandomAccessFileOutStream(raf),itemsCount,callback);
      }
       for (      Closeable c : closeables)       c.close();
      closeables.clear();
    }
    for (    RandomAccessFile raf : rafs.values())     raf.close();
    for (    File tmpfile : tmpfiles.values())     tmpfile.delete();
  }
 else {
    for (    Closeable c : closeables)     c.close();
    closeables.clear();
  }
  try {
    if (tempDir != null)     FileUtils.deleteDirectory(tempDir);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}