#vulnerable code 
                                public static void handleKey(SelectionKey key) {
        ConnectionHandler handler = (ConnectionHandler) key.attachment();
        try {
            if (!key.isValid()) {
                // Key has been cancelled, make sure the socket gets closed
                System.out.println("--------------------destory 1");
                handler.peer.destroy();
                return;
            }
            if (key.isReadable()) {
                // Do a socket read and invoke the connection's receiveBytes message
                int len = handler.channel.read(handler.readBuffer);
                if (len == 0) {
                    // Was probably waiting on a write
                    return;
                } else if (len == -1) {
                    // Socket was closed
                    key.cancel();
                    System.out.println(handler.peer.getIp());
                    System.out.println("--------------------destory 2");
                    handler.peer.destroy();
                    return;
                }
                System.out.println("--------len : " + len);
                // "flip" the buffer - setting the limit to the current position and setting position to 0
                handler.readBuffer.flip();
                handler.peer.receiveMessage(handler.readBuffer);

                // Now drop the bytes which were read by compacting readBuff (resetting limit and keeping relative position)
                handler.readBuffer.compact();
            }
            if (key.isWritable()) {
                handler.writeBytes();
            }
        } catch (Exception e) {
            // This can happen eg if the channel closes while the thread is about to get killed
            // (ClosedByInterruptException), or if handler.connection.receiveBytes throws something
            e.printStackTrace();
            Throwable t = e;
            Log.warn("Error handling SelectionKey: {}", t.getMessage() != null ? t.getMessage() : t.getClass().getName());
            System.out.println("--------------------destory 3");
            handler.peer.destroy();
        }
    } 
                            #location 27 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public static void handleKey(SelectionKey key) {
        ConnectionHandler handler = (ConnectionHandler) key.attachment();
        try {
            if (!key.isValid()) {
                // Key has been cancelled, make sure the socket gets closed
                System.out.println("--------------------destory 1" + handler.peer.getIp());
                handler.peer.destroy();
                return;
            }
            if (key.isReadable()) {
                // Do a socket read and invoke the connection's receiveBytes message
                int len = handler.channel.read(handler.readBuffer);
                if (len == 0) {
                    // Was probably waiting on a write
                    return;
                } else if (len == -1) {
                    // Socket was closed
                    key.cancel();
                    System.out.println("--------------------destory 2" + handler.peer.getIp());
                    handler.peer.destroy();
                    return;
                }
                // "flip" the buffer - setting the limit to the current position and setting position to 0
                handler.readBuffer.flip();
                handler.peer.receiveMessage(handler.readBuffer);

                // Now drop the bytes which were read by compacting readBuff (resetting limit and keeping relative position)
                handler.readBuffer.compact();
            }
            if (key.isWritable()) {
                handler.writeBytes();
            }
        } catch (Exception e) {
            // This can happen eg if the channel closes while the thread is about to get killed
            // (ClosedByInterruptException), or if handler.connection.receiveBytes throws something
            e.printStackTrace();
            Throwable t = e;
            Log.warn("Error handling SelectionKey: {}", t.getMessage() != null ? t.getMessage() : t.getClass().getName());
            System.out.println("--------------------destory 3" + handler.peer.getIp());
            handler.peer.destroy();
        }
    }