atomix / atomix

A Kubernetes toolkit for building distributed applications using cloud native principles

Home Page:https://atomix.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

raft.getCluster().getMember(*).memberId() could Result in an NPE

zhaoyangyingmu opened this issue · comments

Expected behavior
At line 178 of io.atomix.protocols.raft.roles.ActiveRole, the return value of raft.getCluster().getMember(raft.getLastVotedFor()) should be defended by a null check to avoid NullPointerException.

protected VoteResponse handleVote(VoteRequest request) {
    //...
    else {
      log.debug("Rejected {}: already voted for {}", request, raft.getCluster().getMember(raft.getLastVotedFor()).memberId()); // NPE risk
      //...
    }
}

Actual behavior & Steps to reproduce
raft.getCluster().getMember(raft.getLastVotedFor()) could return null when raft's last vote has no corresponding DefaultRaftMember and it's dereferenced unconditionally.

Minimal yet complete reproducer code (or URL to code)

protected VoteResponse handleVote(VoteRequest request) {
    //...
    else {
      DefaultRaftMember member = request, raft.getCluster().getMember(raft.getLastVotedFor());
      log.debug("Rejected {}: already voted for {}", member == null? null:member.memberId()); // NPE risk
      //...
    }
}

Environment

  • Atomix: default master
  • OS: [e.g. uname -a]
  • JVM [e.g. java -version]

⚠️️ Please verify that your issue still occurs on the latest version of Atomix before reporting.
The documentation is currently work-in-progress and is not yet complete.


Have you searched the CLOSED issues already? How about checking in with the Atomix Google Group?