zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ZOOKEEPER-3010) Potential NPE in Observer#observeLeader and Follower#followLeader
Date Sun, 22 Apr 2018 07:24:00 GMT

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-3010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16447126#comment-16447126
] 

ASF GitHub Bot commented on ZOOKEEPER-3010:
-------------------------------------------

GitHub user brettKK opened a pull request:

    https://github.com/apache/zookeeper/pull/504

    Potential NPE in Observer#observeLeader and Follower#followLeader

    Bug description:
    
    callee Learner#findLeader will return null and callee developer check it but just log:
    ```
    // code placeholder
    if (leaderServer == null) {
       LOG.warn("Couldn't find the leader with id = " + current.getId());
    }
    return leaderServer;
    ```
    
    caller  Observer#observeLeader and Follower#followLeader will directly use return value
w/o null check:
    ```
    //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);
    }
    ```
    
    https://issues.apache.org/jira/browse/ZOOKEEPER-3010

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/brettKK/zookeeper ZOOK-3010

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/zookeeper/pull/504.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #504
    
----
commit 7d8d5230c5a87faef94d038a258b159a322f3f5e
Author: gongleigl.gong <gongleigl.gong@...>
Date:   2018-03-26T13:16:06Z

    d

commit 700dfb7f48f774dd215e5bf19340a4b61eda3397
Author: gongleigl.gong <gongleigl.gong@...>
Date:   2018-03-27T16:38:28Z

    fix NPE bug

commit f71d8ce153d393dc3ab13c62d9d374e8a4aeb1cf
Author: brettkk <1099446733@...>
Date:   2018-04-22T07:19:21Z

    zook3010

----


> 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