#vulnerable code 
                                public void addObject(Object key) throws Exception {
        assertOpen();
        if (_factory == null) {
            throw new IllegalStateException("Cannot add objects without a factory.");
        }
        Object obj = _factory.makeObject(key);
        synchronized (this) {
            try {
                assertOpen();
                addObjectToPool(key, obj, false);
            } catch (IllegalStateException ex) { // Pool closed
                try {
                    _factory.destroyObject(key, obj);
                } catch (Exception ex2) {
                    // swallow
                }
                throw ex;
            }
        }
    } 
                            #location 6 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public void addObject(Object key) throws Exception {
        assertOpen();
        if (_factory == null) {
            throw new IllegalStateException("Cannot add objects without a factory.");
        }
        Object obj = _factory.makeObject(key);
        try {
            assertOpen();
            addObjectToPool(key, obj, false);
        } catch (IllegalStateException ex) { // Pool closed
            try {
                _factory.destroyObject(key, obj);
            } catch (Exception ex2) {
                // swallow
            }
            throw ex;
        }
    }