#fixed code
                                @Override
    public boolean waitForIncomingEmail(long timeout, int emailCount) {
        final CountDownLatch waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount);
        final long endTime = System.currentTimeMillis() + timeout;
            while (waitObject.getCount() > 0) {
                final long waitTime = endTime - System.currentTimeMillis();
                if (waitTime < 0L) {
                    return waitObject.getCount() == 0;
                }
                try {
                    waitObject.await(waitTime, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    // Continue loop, in case of premature interruption
                }
            }
        return waitObject.getCount() == 0;
    }
#vulnerable code 
                                @Override
    public boolean waitForIncomingEmail(long timeout, int emailCount) {
        final SmtpManager.WaitObject waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount);
        final long endTime = System.currentTimeMillis() + timeout;
        synchronized (waitObject) {
            while (!waitObject.isArrived()) {
                final long waitTime = endTime - System.currentTimeMillis();
                if (waitTime < 0L) {
                    return waitObject.isArrived();
                }
                //this loop is necessary to insure correctness, see documentation on Object.wait()
                try {
                    waitObject.wait(waitTime);
                } catch (InterruptedException e) {
                    throw new IllegalStateException("Interrupted while waiting for incoming email", e);
                }
            }
        }
        return waitObject.isArrived();
    } 
                            #location 3 
                            #vulnerability type THREAD_SAFETY_VIOLATION