#fixed code
                                public void evict() throws Exception {
        assertOpen();

        if (_pool.size() == 0) {
            return;
        }
        
        PooledObject<T> underTest = null;
        
        for (int i = 0, m = getNumTests(); i < m; i++) {
            if (_evictionIterator == null || !_evictionIterator.hasNext()) {
                if (getLifo()) {
                    _evictionIterator = _pool.descendingIterator();
                } else {
                    _evictionIterator = _pool.iterator();
                }
            }
            if (!_evictionIterator.hasNext()) {
                // Pool exhausted, nothing to do here
                return;
            } else {
                try {
                    underTest = _evictionIterator.next();
                } catch (NoSuchElementException nsee) {
                    // Object was borrowed in another thread
                    // Don't count this as an eviction test so reduce i;
                    i--;
                    _evictionIterator = null;
                    continue;
                }
            }

            if (!underTest.startEvictionTest()) {
                // Object was borrowed in another thread
                // Don't count this as an eviction test so reduce i;
                i--;
                continue;
            }
            
            if (getMinEvictableIdleTimeMillis() > 0 &&
                        getMinEvictableIdleTimeMillis() <
                            underTest.getIdleTimeMillis() ||
                    (getSoftMinEvictableIdleTimeMillis() > 0 &&
                            getSoftMinEvictableIdleTimeMillis() <
                                underTest.getIdleTimeMillis() &&
                            getMinIdle() < _pool.size())) {
                destroy(underTest);
            } else {
                if (getTestWhileIdle()) {
                    boolean active = false;
                    try {
                        _factory.activateObject(underTest.getObject());
                        active = true;
                    } catch(Exception e) {
                        destroy(underTest);
                    }
                    if(active) {
                        if(!_factory.validateObject(underTest.getObject())) {
                            destroy(underTest);
                        } else {
                            try {
                                _factory.passivateObject(underTest.getObject());
                            } catch(Exception e) {
                                destroy(underTest);
                            }
                        }
                    }
                }
                if (!underTest.endEvictionTest()) {
                    // TODO - May need to add code here once additional states
                    // are used
                }
            }
        }

        return;
    }
#vulnerable code 
                                public void evict() throws Exception {
        assertOpen();
        synchronized (this) {
            if(_pool.isEmpty()) {
                return;
            }
            if (null == _evictionCursor) {
                _evictionCursor = (_pool.cursor(_lifo ? _pool.size() : 0));
            }
        }

        for (int i=0,m=getNumTests();i<m;i++) {
            final ObjectTimestampPair<T> pair;
            synchronized (this) {
                if ((_lifo && !_evictionCursor.hasPrevious()) ||
                        !_lifo && !_evictionCursor.hasNext()) {
                    _evictionCursor.close();
                    _evictionCursor = _pool.cursor(_lifo ? _pool.size() : 0);
                }

                pair = _lifo ?
                        _evictionCursor.previous() :
                        _evictionCursor.next();

                _evictionCursor.remove();
                _numInternalProcessing++;
            }

            boolean removeObject = false;
            final long idleTimeMilis = System.currentTimeMillis() - pair.getTstamp();
            if ((getMinEvictableIdleTimeMillis() > 0) &&
                    (idleTimeMilis > getMinEvictableIdleTimeMillis())) {
                removeObject = true;
            } else if ((getSoftMinEvictableIdleTimeMillis() > 0) &&
                    (idleTimeMilis > getSoftMinEvictableIdleTimeMillis()) &&
                    ((getNumIdle() + 1)> getMinIdle())) { // +1 accounts for object we are processing
                removeObject = true;
            }
            if(getTestWhileIdle() && !removeObject) {
                boolean active = false;
                try {
                    _factory.activateObject(pair.getValue());
                    active = true;
                } catch(Exception e) {
                    removeObject=true;
                }
                if(active) {
                    if(!_factory.validateObject(pair.getValue())) {
                        removeObject=true;
                    } else {
                        try {
                            _factory.passivateObject(pair.getValue());
                        } catch(Exception e) {
                            removeObject=true;
                        }
                    }
                }
            }

            if (removeObject) {
                try {
                    _factory.destroyObject(pair.getValue());
                } catch(Exception e) {
                    // ignored
                }
            }
            synchronized (this) {
                if(!removeObject) {
                    _evictionCursor.add(pair);
                    if (_lifo) {
                        // Skip over the element we just added back
                        _evictionCursor.previous();
                    }
                }
                _numInternalProcessing--;
            }
        }
        allocate();
    } 
                            #location 12 
                            #vulnerability type THREAD_SAFETY_VIOLATION