zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lujiefsi <...@git.apache.org>
Subject [GitHub] zookeeper pull request #525: [ZOOKEEPER-3009] Potential NPE in NIOServerCnxn...
Date Mon, 21 May 2018 01:52:04 GMT
GitHub user lujiefsi opened a pull request:

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

    [ZOOKEEPER-3009] Potential NPE in NIOServerCnxnFactory

    We have developed a static analysis tool NPEDetector to find some potential NPE. Our analysis
shows that NPE reason can be simple:some callees may return null directly in corner case(e.g.
node crash , IO exception), some of their callers have  !=null check but some do not have.

    ### Bug:
    Callee getSocketAddress can return null, may caused by node crash, network exception....
    <pre>
        public InetAddress getSocketAddress() {
            if (sock.isOpen() == false) {
                return null;
            }
            return sock.socket().getInetAddress();
        }
    </pre>
    
    caller removeCnxn has null check
    <pre>
     public boolean removeCnxn(NIOServerCnxn cnxn) {
            //other code
            InetAddress addr = cnxn.getSocketAddress();
            if (addr != null) {
                Set<NIOServerCnxn> set = ipMap.get(addr);
                //other code
            }
         //other code
        }
    </pre>
    
    but caller addCnxn has them similar code, but don't have the null check:
    <pre>
         private void addCnxn(NIOServerCnxn cnxn) {
             InetAddress addr = cnxn.getSocketAddress();
             Set<NIOServerCnxn> set = ipMap.get(addr);
            //other code
          }
    </pre>

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

    $ git pull https://github.com/lujiefsi/zookeeper ZOOKEEPER-3009

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

    https://github.com/apache/zookeeper/pull/525.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 #525
    
----
commit 8bfad14efaa885818dbf45a33c9ad8b55d3901e4
Author: LJ1043041006 <1239497420@...>
Date:   2018-05-21T01:41:13Z

    [ZOOKEEPER-3009] Potential NPE in NIOServerCnxnFactory

----


---

Mime
View raw message