Buggy code:
public class Raft implements StateLog < Bytes > { private static final long LOG_CACHE_SIZE = 10 ; private static final LogEntry LOG_HEAD = new DefaultLogEntry ( 0 , 0 , null , null ) ; private final Logger logger ; private final StateStorage stateStorage ; private final Log log ; private final ScheduledExecutorService scheduler ; private final ExecutorService executor ; private final ChannelListener < RaftMessage > channelListener ; private final Random random ; private final Lock stateLock ; private final String id ; private final Map < String , Node < RaftMessage > > nodes ; private final Node < RaftMessage > self ; private ScheduledFuture < ? > electionTimeout ; private ScheduledFuture < ? > heartbeat ; private Raft . Role role ; private final Set < String > votes ; private Node < RaftMessage > leader ; private final Map < String , Raft . NodeState > nodeStates ; private long commitIndex ; private long lastApplied ; private final Thread applierThread ; private final Condition commitIndexUpdated ; private final LongObjectMap < CompletableFuture < Void > > futures ; private final IoConsumer < Bytes > applier ; private final boolean applierVolatile ; private final List < NodeEvent < RaftMessage > > nodeChanges ; public Raft ( StateStorage stateStorage , Log log , Nodes < RaftMessage > nodes , String id , IoConsumer < Bytes > applier , boolean applierVolatile ) { } private void uncaughtException ( Thread t , Throwable e ) { } private ChannelListener < RaftMessage > createChannelListener ( ) { } private void handleNodeEvent ( NodeEvent < RaftMessage > event ) { } @ Override public void close ( ) { } @ Override public CompletableFuture < Void > submit ( Bytes entry ) { } private CompletableFuture < Void > requestAppendEntry ( Bytes data ) { } private CompletableFuture < Void > forwardAppendEntryToLeader ( Bytes data ) { } private void handleRequestVote ( Node < RaftMessage > node , RequestVote message ) { } private void handleRequestVoteReply ( Node < RaftMessage > node , RequestVoteReply reply ) { } private void maybeBecomeLeader ( ) { if ( ( ( role ) != ( Raft . Role . LEADER ) ) && ( isMajority ( votes . size ( ) , nodes . size ( ) ) ) ) { cancelElectionTimeout ( ) ; role = Raft . Role . LEADER ; leader = self ; logger . debug ( ( ( ( ( "Became<seq2seq4repair_space>leader,<seq2seq4repair_space>due<seq2seq4repair_space>to<seq2seq4repair_space>having<seq2seq4repair_space>" + ( votes . size ( ) ) ) + "<seq2seq4repair_space>votes<seq2seq4repair_space>of<seq2seq4repair_space>" ) + ( nodes . size ( ) ) ) + "<seq2seq4repair_space>total" ) ) ; LogEntry lastLogEntry = getLastLogEntry ( ) ; for ( Node < RaftMessage > n : nodes . values ( ) ) { nodeStates . put ( n . getId ( ) , new Raft . NodeState ( ( ( lastLogEntry . getIndex ( ) ) + 1 ) ) ) ; } <START_BUG> Raft . NodeState state = nodeStates . get ( self ) ; <END_BUG> state . matchIndex = lastLogEntry . getIndex ( ) ; updateCommitIndex ( ) ; sendHeartbeat ( ) ; scheduleSendHeartbeat ( ) ; } } private boolean isMajority ( int votes , int total ) { } private void handleAppendEntries ( Node < RaftMessage > node , AppendEntries message ) { } private void handleAppendEntriesReply ( Node < RaftMessage > node , AppendEntriesReply message ) { } private void updateCommitIndex ( ) { } private void commitUpTo ( long index ) { } private void applyCommitableEntries ( ) { } private void switchRoleToFollower ( long term ) { } private LogEntry getLastLogEntry ( ) { } private LogEntry getLogEntry ( long id ) { } private void sendHeartbeat ( ) { } private void sendAppendEntries ( Node < RaftMessage > node ) { } private void sendAppendEntries ( Node < RaftMessage > node , long term , LogEntry lastLogEntry ) throws IOException { } private void startElection ( ) { } private boolean cancelElectionTimeout ( ) { } private void scheduleElectionTimeout ( ) { } private void scheduleHearbeatElection ( ) { } private void scheduleSendHeartbeat ( ) { } private void sendToAll ( RaftMessage msg ) { } private void sendTo ( Node < RaftMessage > node , RaftMessage msg ) { } enum Role { FOLLOWER , CANDIDATE , LEADER ; } private static class NodeState { private long nextIndex ; private long matchIndex ; public NodeState ( long nextIndex ) { } } }

Fix:
Raft . NodeState state = nodeStates . get ( self . getId ( ) ) ;