#vulnerable code 
                                @Override
    public void close() {
        if (!connected.compareAndSet(true, false)) return;
        if (heartBeat != null) {
            heartBeat.cancel();
            heartBeat = null;
            logger.info("heart beat canceled.");
        }
        try {
            if (inputStream != null) inputStream.close();
        } catch (IOException e) {
            //NOP
        }
        try {
            if (outputStream != null) outputStream.close();
        } catch (IOException e) {
            //NOP
        }
        try {
            if (socket != null && !socket.isClosed()) socket.close();
        } catch (IOException e) {
            //NOP
        }
        logger.info("channel closed");
    } 
                            #location 10 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                @Override
    public void close() {
        if (!connected.compareAndSet(true, false)) return;

        synchronized (this) {
            if (heartBeat != null) {
                heartBeat.cancel();
                heartBeat = null;
                logger.info("heart beat canceled.");
            }
        }

        try {
            if (inputStream != null) inputStream.close();
        } catch (IOException e) {
            //NOP
        }
        try {
            if (outputStream != null) outputStream.close();
        } catch (IOException e) {
            //NOP
        }
        try {
            if (socket != null && !socket.isClosed()) socket.close();
        } catch (IOException e) {
            //NOP
        }
        logger.info("channel closed");
    }