#vulnerable code 
                                @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        SocketChannel channel = (SocketChannel) ctx.channel();
        String nodeId = IpUtil.getNodeId(channel.remoteAddress());
        Log.debug("---------------------- server channelRegistered ------------------------- " + nodeId);
        String remoteIP = channel.remoteAddress().getHostString();
//        String remoteId = IpUtil.getNodeId(channel.remoteAddress());
//        Node node = getNetworkService().getNode(remoteId);
//        if (node != null) {
//            if (node.getStatus() == Node.CONNECT) {
//                ctx.channel().close();
//                return;
//            }
//            //When nodes try to connect to each other but not connected, select one of the smaller IP addresses as the server
////            if (node.getType() == Node.OUT) {
////                String localIP = InetAddress.getLocalHost().getHostAddress();
////                boolean isLocalServer = IpUtil.judgeIsLocalServer(localIP, remoteIP);
////
////                if (!isLocalServer) {
////                    ctx.channel().close();
////                    return;
////                } else {
////                    getNetworkService().removeNode(remoteId);
////                }
////            }
//        } else {
        // if has a node with same ip, and it's a out node, close this channel
        // if More than 10 in nodes of the same IP, close this channel
        int count = 0;
        for (Node n : getNetworkService().getNodes().values()) {
            if (n.getIp().equals(remoteIP)) {
                count++;
                if (count >= Node.SAME_IP_MAX_COUNT) {
                    ctx.channel().close();
                    return;
                }
//
//                if (n.getType() == Node.OUT && n.getStatus() == Node.HANDSHAKE) {
//                    ctx.channel().close();
//                    return;
//                } else {
//                    count++;
//                    if (count == 10) {
//                        ctx.channel().close();
//                        return;
//                    }
//                }
            }
        }
    } 
                            #location 30 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        SocketChannel channel = (SocketChannel) ctx.channel();
        String nodeId = IpUtil.getNodeId(channel.remoteAddress());
//        Log.info("---------------------- server channelRegistered ------------------------- " + nodeId);
        String remoteIP = channel.remoteAddress().getHostString();

        NodeGroup outGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP);
        for (Node node : outGroup.getNodes().values()) {
            if (node.getIp().equals(remoteIP)) {
                String localIP = InetAddress.getLocalHost().getHostAddress();
                boolean isLocalServer = IpUtil.judgeIsLocalServer(localIP, remoteIP);

                if (!isLocalServer) {
                    ctx.channel().close();
                    return;
                } else {
                    getNetworkService().removeNode(node.getId());
                }
            }
        }
        // if has a node with same ip, and it's a out node, close this channel
        // if More than 10 in nodes of the same IP, close this channel
        int count = 0;
        for (Node n : getNetworkService().getNodes().values()) {
            if (n.getIp().equals(remoteIP)) {
                count++;
                if (count >= Node.SAME_IP_MAX_COUNT) {
                    ctx.channel().close();
                    return;
                }
//
//                if (n.getType() == Node.OUT && n.getStatus() == Node.HANDSHAKE) {
//                    ctx.channel().close();
//                    return;
//                } else {
//                    count++;
//                    if (count == 10) {
//                        ctx.channel().close();
//                        return;
//                    }
//                }
            }
        }
    }