#vulnerable code 
                                @Override
    public void replaceIndex(String newLuceneIndexPathString) {
        LOG.debug(
                "Replacing Lucene indexes at {} for dimension {} with new index at {}",
                luceneDirectory.toString(),
                dimension.getApiName(),
                newLuceneIndexPathString
        );

        lock.writeLock().lock();
        try {
            Path oldLuceneIndexPath = Paths.get(luceneIndexPath);
            String tempDir = oldLuceneIndexPath.resolveSibling(oldLuceneIndexPath.getFileName() + "_old").toString();

            LOG.trace("Moving old Lucene index directory from {} to {} ...", luceneIndexPath, tempDir);
            moveDirEntries(luceneIndexPath, tempDir);

            LOG.trace("Moving all new Lucene indexes from {} to {} ...", newLuceneIndexPathString, luceneIndexPath);
            moveDirEntries(newLuceneIndexPathString, luceneIndexPath);

            LOG.trace(
                    "Deleting {} since new Lucene indexes have been moved away from there and is now empty",
                    newLuceneIndexPathString
            );
            deleteDir(newLuceneIndexPathString);

            LOG.trace("Deleting old Lucene indexes in {} ...", tempDir);
            deleteDir(tempDir);

            reopenIndexSearcher(false);
        } finally {
            lock.writeLock().unlock();
        }
    } 
                            #location 6 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                @Override
    public void replaceIndex(String newLuceneIndexPathString) {
        LOG.debug(
                "Replacing Lucene indexes at {} for dimension {} with new index at {}",
                luceneDirectory.toString(),
                dimension.getApiName(),
                newLuceneIndexPathString
        );

        writeLock();
        try {
            Path oldLuceneIndexPath = Paths.get(luceneIndexPath);
            String tempDir = oldLuceneIndexPath.resolveSibling(oldLuceneIndexPath.getFileName() + "_old").toString();

            LOG.trace("Moving old Lucene index directory from {} to {} ...", luceneIndexPath, tempDir);
            moveDirEntries(luceneIndexPath, tempDir);

            LOG.trace("Moving all new Lucene indexes from {} to {} ...", newLuceneIndexPathString, luceneIndexPath);
            moveDirEntries(newLuceneIndexPathString, luceneIndexPath);

            LOG.trace(
                    "Deleting {} since new Lucene indexes have been moved away from there and is now empty",
                    newLuceneIndexPathString
            );
            deleteDir(newLuceneIndexPathString);

            LOG.trace("Deleting old Lucene indexes in {} ...", tempDir);
            deleteDir(tempDir);

            reopenIndexSearcher(false);
        } finally {
            writeUnlock();
        }
    }