#vulnerable code 
                                public void replicate(byte[] data) {
        Raft.LogEntry logEntry = Raft.LogEntry.newBuilder()
                .setTerm(currentTerm)
                .setType(Raft.EntryType.ENTRY_TYPE_DATA)
                .setData(ByteString.copyFrom(data)).build();
        List<Raft.LogEntry> entries = new ArrayList<>();
        entries.add(logEntry);
        long newLastLogIndex = raftLog.append(entries);
        for (final Peer peer : peers) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    appendEntries(peer);
                }
            });
        }
        // sync wait condition commitIndex >= newLastLogIndex
        // TODO: add timeout
        lock.lock();
        try {
            while (commitIndex < newLastLogIndex) {
                try {
                    commitIndexCondition.await();
                } catch (InterruptedException ex) {
                    LOG.warn(ex.getMessage());
                }
            }
        } finally {
            lock.unlock();
        }
    } 
                            #location 3 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public void replicate(byte[] data) {
        lock.lock();
        Raft.LogEntry logEntry = Raft.LogEntry.newBuilder()
                .setTerm(currentTerm)
                .setType(Raft.EntryType.ENTRY_TYPE_DATA)
                .setData(ByteString.copyFrom(data)).build();
        List<Raft.LogEntry> entries = new ArrayList<>();
        entries.add(logEntry);
        long newLastLogIndex = raftLog.append(entries);
        for (final Peer peer : peers) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    appendEntries(peer);
                }
            });
        }
        // sync wait condition commitIndex >= newLastLogIndex
        // TODO: add timeout
        try {
            while (commitIndex < newLastLogIndex) {
                try {
                    commitIndexCondition.await();
                } catch (InterruptedException ex) {
                    LOG.warn(ex.getMessage());
                }
            }
        } finally {
            lock.unlock();
        }
    }