#vulnerable code 
                                @Override
    public void run() {
        try {
            try {
                serverSocket = openServerSocket();
                setRunning(true);
                synchronized (this) {
                    this.notifyAll();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            while (keepOn()) {
                try {
                    Socket clientSocket = serverSocket.accept();
                    if (!keepOn()) {
                        clientSocket.close();
                    } else {
                        final ProtocolHandler handler = createProtocolHandler(clientSocket);
                        addHandler(handler);
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                handler.run(); // NOSONAR
                                 // Make sure to deregister, see https://github.com/greenmail-mail-test/greenmail/issues/18
                                removeHandler(handler);
                            }
                        }).start();
                    }
                } catch (IOException ignored) {
                    //ignored
                    if(log.isTraceEnabled()) {
                        log.trace("Error while processing socket", ignored);
                    }
                }
            }
        } finally {
            quit();
        }
    } 
                            #location 16 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                @Override
    public void run() {
        try {
            serverSocket = openServerSocket();
            setRunning(true);
            synchronized (this) {
                this.notifyAll();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        while (keepOn()) {
            try {
                Socket clientSocket = serverSocket.accept();
                if (!keepOn()) {
                    clientSocket.close();
                } else {
                    final ProtocolHandler handler = createProtocolHandler(clientSocket);
                    addHandler(handler);
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            handler.run(); // NOSONAR
                             // Make sure to deregister, see https://github.com/greenmail-mail-test/greenmail/issues/18
                            removeHandler(handler);
                        }
                    }).start();
                }
            } catch (IOException ignored) {
                //ignored
                if(log.isTraceEnabled()) {
                    log.trace("Error while processing socket", ignored);
                }
            }
        }
    }