#vulnerable code 
                                public ManagerResponse sendAction(ManagerAction action, long timeout)
            throws IOException, TimeoutException, IllegalArgumentException,
            IllegalStateException
    {
        long start;
        long timeSpent;
        ResponseHandlerResult result;
        ManagerResponseHandler callbackHandler;

        result = new ResponseHandlerResult();
        callbackHandler = new DefaultResponseHandler(result, Thread
                .currentThread());

        sendAction(action, callbackHandler);

        start = System.currentTimeMillis();
        timeSpent = 0;
        while (result.getResponse() == null)
        {
            try
            {
                Thread.sleep(timeout - timeSpent);
            }
            catch (InterruptedException ex)
            {
            }

            // still no response and timed out?
            timeSpent = System.currentTimeMillis() - start;
            if (result.getResponse() == null && timeSpent > timeout)
            {
                throw new TimeoutException("Timeout waiting for response to "
                        + action.getAction());
            }
        }

        return result.getResponse();
    } 
                            #location 14 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public ManagerResponse sendAction(ManagerAction action, long timeout)
            throws IOException, TimeoutException, IllegalArgumentException,
            IllegalStateException
    {
        ResponseHandlerResult result;
        ManagerResponseHandler callbackHandler;

        result = new ResponseHandlerResult();
        callbackHandler = new DefaultResponseHandler(result);

        synchronized (result)
        {
            sendAction(action, callbackHandler);
            try
            {
                result.wait(timeout);
            }
            catch (InterruptedException ex)
            {
                //TODO fix logging
                System.err.println("Interrupted!");
            }
        }
    
        // still no response?
        if (result.getResponse() == null)
        {
            throw new TimeoutException("Timeout waiting for response to "
                    + action.getAction());
        }

        return result.getResponse();
    }