Program: 154778
Project: 154778
Buggy source:
@Override protected void doCommit(){
  dataSource.getWriteLock();
  try {
    for (    Map.Entry<IndexIdentifier,CommandList> entry : this.commandMap.entrySet()) {
      IndexIdentifier identifier=entry.getKey();
      IndexType type=identifier == LuceneCommand.CreateIndexCommand.FAKE_IDENTIFIER ? null : dataSource.getType(identifier);
      IndexWriter writer=null;
      IndexSearcher searcher=null;
      CommandList commandList=entry.getValue();
      Map<Long,DocumentContext> documents=new HashMap<Long,DocumentContext>();
      for (      LuceneCommand command : commandList.commands) {
        if (command instanceof CreateIndexCommand) {
          CreateIndexCommand createCommand=(CreateIndexCommand)command;
          dataSource.indexStore.setIfNecessary(createCommand.getName(),createCommand.getConfig());
          continue;
        }
        if (writer == null) {
          writer=dataSource.getIndexWriter(identifier);
          writer.setMaxBufferedDocs(commandList.addCount + 100);
          writer.setMaxBufferedDeleteTerms(commandList.removeCount + 100);
          searcher=dataSource.getIndexSearcher(identifier).getSearcher();
        }
        if (command instanceof ClearCommand) {
          documents.clear();
          dataSource.closeWriter(writer);
          writer=null;
          dataSource.deleteIndex(identifier);
          dataSource.invalidateCache(identifier);
          continue;
        }
        Object entityId=command.entityId;
        long id=entityId instanceof Long ? (Long)entityId : ((RelationshipId)entityId).id;
        DocumentContext context=documents.get(id);
        if (context == null) {
          Document document=LuceneDataSource.findDocument(type,searcher,id);
          context=document == null ? new DocumentContext(identifier.entityType.newDocument(entityId),false,id) : new DocumentContext(document,true,id);
          documents.put(id,context);
        }
        String key=command.key;
        Object value=command.value;
        if (command instanceof AddCommand || command instanceof AddRelationshipCommand) {
          type.addToDocument(context.document,key,value);
          dataSource.invalidateCache(identifier,key,value);
        }
 else         if (command instanceof RemoveCommand) {
          type.removeFromDocument(context.document,key,value);
          dataSource.invalidateCache(identifier,key,value);
        }
 else {
          throw new RuntimeException("String_Node_Str" + command + "String_Node_Str"+ command.getClass());
        }
      }
      applyDocuments(writer,type,documents);
      if (writer != null) {
        dataSource.closeWriter(writer);
      }
      dataSource.invalidateIndexSearcher(identifier);
    }
    closeTxData();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
 finally {
    dataSource.releaseWriteLock();
  }
}

Fixed version (ground truth):
@Override protected void doCommit(){
  dataSource.getWriteLock();
  try {
    for (    Map.Entry<IndexIdentifier,CommandList> entry : this.commandMap.entrySet()) {
      if (entry.getValue().isEmpty()) {
        continue;
      }
      boolean isRecovery=entry.getValue().isRecovery();
      IndexIdentifier identifier=entry.getKey();
      IndexType type=identifier == LuceneCommand.CreateIndexCommand.FAKE_IDENTIFIER ? null : dataSource.getType(identifier);
      IndexWriter writer=null;
      IndexSearcher searcher=null;
      CommandList commandList=entry.getValue();
      Map<Long,DocumentContext> documents=new HashMap<Long,DocumentContext>();
      for (      LuceneCommand command : commandList.commands) {
        if (command instanceof CreateIndexCommand) {
          CreateIndexCommand createCommand=(CreateIndexCommand)command;
          dataSource.indexStore.setIfNecessary(createCommand.getName(),createCommand.getConfig());
          continue;
        }
        if (writer == null) {
          if (isRecovery) {
            writer=dataSource.getRecoveryIndexWriter(identifier);
          }
 else {
            writer=dataSource.getIndexWriter(identifier);
            writer.setMaxBufferedDocs(commandList.addCount + 100);
            writer.setMaxBufferedDeleteTerms(commandList.removeCount + 100);
          }
          searcher=dataSource.getIndexSearcher(identifier).getSearcher();
        }
        if (command instanceof ClearCommand) {
          documents.clear();
          dataSource.closeWriter(writer);
          writer=null;
          dataSource.deleteIndex(identifier);
          dataSource.invalidateCache(identifier);
          if (isRecovery) {
            dataSource.removeRecoveryIndexWriter(identifier);
          }
          continue;
        }
        Object entityId=command.entityId;
        long id=entityId instanceof Long ? (Long)entityId : ((RelationshipId)entityId).id;
        DocumentContext context=documents.get(id);
        if (context == null) {
          Document document=LuceneDataSource.findDocument(type,searcher,id);
          context=document == null ? new DocumentContext(identifier.entityType.newDocument(entityId),false,id) : new DocumentContext(document,true,id);
          documents.put(id,context);
        }
        String key=command.key;
        Object value=command.value;
        if (command instanceof AddCommand || command instanceof AddRelationshipCommand) {
          type.addToDocument(context.document,key,value);
          dataSource.invalidateCache(identifier,key,value);
        }
 else         if (command instanceof RemoveCommand) {
          type.removeFromDocument(context.document,key,value);
          dataSource.invalidateCache(identifier,key,value);
        }
 else {
          throw new RuntimeException("String_Node_Str" + command + "String_Node_Str"+ command.getClass());
        }
      }
      applyDocuments(writer,type,documents);
      if (writer != null && !isRecovery) {
        dataSource.closeWriter(writer);
        dataSource.invalidateIndexSearcher(identifier);
      }
    }
    closeTxData();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
 finally {
    dataSource.releaseWriteLock();
  }
}