zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "lujie (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (ZOOKEEPER-3010) Potential NPE in Observer#observeLeader and Follower#followLeader
Date Mon, 26 Mar 2018 08:20:00 GMT

     [ https://issues.apache.org/jira/browse/ZOOKEEPER-3010?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

lujie updated ZOOKEEPER-3010:
-----------------------------
    Description: 
After ZK-3006 , I develop a very simple static analysis tool to find other Potential NPE
like ZK-3006, this bug is found by this tool and  carefully studied by myself, hopefully
someone can confirm it and help me improve this tool.
h2. Bug description:

callee Learner#findLeader will return null and callee developer check it but just log:
{code:java}
// code placeholder
if (leaderServer == null) {
   LOG.warn("Couldn't find the leader with id = " + current.getId());
}
return leaderServer;
{code}
caller  Observer#observeLeader and Follower#followLeader will directly use return value
w/o null check:
{code:java}
//Follower#followLeader
QuorumServer leaderServer = findLeader();
try {
    connectToLeader(leaderServer.addr, leaderServer.hostname);
    ..........
}
//Observer#observeLeader
QuorumServer leaderServer = findLeader();
LOG.info("Observing " + leaderServer.addr);
try {
    connectToLeader(leaderServer.addr, leaderServer.hostname);
}{code}

  was:
After ZK-3006 , I develop a very simple static analysis tool to find other Potential NPE
like ZK-3006, this bug is found by this tool and  carefully studied by myself, hopefully
someone can confirm it.
h2. Bug description:

callee Learner#findLeader will return null and callee developer check it but just log:
{code:java}
// code placeholder
if (leaderServer == null) {
   LOG.warn("Couldn't find the leader with id = " + current.getId());
}
return leaderServer;
{code}
caller  Observer#observeLeader and Follower#followLeader will directly use return value
w/o null check:
{code:java}
//Follower#followLeader
QuorumServer leaderServer = findLeader();
try {
    connectToLeader(leaderServer.addr, leaderServer.hostname);
    ..........
}
//Observer#observeLeader
QuorumServer leaderServer = findLeader();
LOG.info("Observing " + leaderServer.addr);
try {
    connectToLeader(leaderServer.addr, leaderServer.hostname);
}{code}


> Potential NPE in Observer#observeLeader and Follower#followLeader
> -----------------------------------------------------------------
>
>                 Key: ZOOKEEPER-3010
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3010
>             Project: ZooKeeper
>          Issue Type: Bug
>    Affects Versions: 3.6.0
>         Environment:  
>  
>            Reporter: lujie
>            Priority: Major
>
> After ZK-3006 , I develop a very simple static analysis tool to find other Potential
NPE like ZK-3006, this bug is found by this tool and  carefully studied by myself, hopefully
someone can confirm it and help me improve this tool.
> h2. Bug description:
> callee Learner#findLeader will return null and callee developer check it but just log:
> {code:java}
> // code placeholder
> if (leaderServer == null) {
>    LOG.warn("Couldn't find the leader with id = " + current.getId());
> }
> return leaderServer;
> {code}
> caller  Observer#observeLeader and Follower#followLeader will directly use return value
w/o null check:
> {code:java}
> //Follower#followLeader
> QuorumServer leaderServer = findLeader();
> try {
>     connectToLeader(leaderServer.addr, leaderServer.hostname);
>     ..........
> }
> //Observer#observeLeader
> QuorumServer leaderServer = findLeader();
> LOG.info("Observing " + leaderServer.addr);
> try {
>     connectToLeader(leaderServer.addr, leaderServer.hostname);
> }{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message