Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-3009

Potential NPE in NIOServerCnxnFactory

    XMLWordPrintableJSON

    Details

      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.

      Bug description:

       class NIOServerCnxn has three method :getSocketAddress,getRemoteSocketAddress can return null just like :

      // code placeholder
      if (sock.isOpen() == false) {
        return null;
      }
      

      some of their caller give null checker, some(total 3 list in below) are not. 

      // ServerCnxn#getConnectionInfo
      Map<String, Object> info = new LinkedHashMap<String, Object>();
      info.put("remote_socket_address", getRemoteSocketAddress());// Map.put will throw NPE if parameter is null
      
      //IPAuthenticationProvider#handleAuthentication
      tring id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress();
      cnxn.addAuthInfo(new Id(getScheme(), id));// finally call Set.add(it will throw NPE if parameter is null )
      
      //NIOServerCnxnFactory#addCnxn
      InetAddress addr = cnxn.getSocketAddress();
      Set<NIOServerCnxn> set = ipMap.get(addr);// Map.get will throw NPE if parameter is null

      I think we should add null check in above three caller .

       

        Attachments

          Activity

            People

            • Assignee:
              xiaoheipangzi lujie
              Reporter:
              xiaoheipangzi lujie
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h
                2h