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 09:34:00 GMT

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

lujie updated ZOOKEEPER-3010:
-----------------------------
    Description: 
Inspired by ZK-3006 , I develop a simple static analysis tool to find other Potential NPE
like ZK-3006. This bug is found by this tool ,and I have carefully studied it.  But i am
a newbie at here so i may be wrong, hope someone could 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:
Inspired by ZK-3006 , I develop a simple static analysis tool to find other Potential NPE
like ZK-3006. This bug is found by this tool , I carefully studied it,  but i am a newbie
here so i may be wrong, hopefully someone can confirm this bug 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}


> 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
>
> Inspired by ZK-3006 , I develop a simple static analysis tool to find other Potential
NPE like ZK-3006. This bug is found by this tool ,and I have carefully studied it.  But i
am a newbie at here so i may be wrong, hope someone could 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