#vulnerable code 
                                public void commit(Transaction transaction) throws RollbackException, TransactionException {
        if (LOG.isTraceEnabled()) {
            LOG.trace("commit " + transaction);
        }

        // Check rollbackOnly status
        if (transaction.isRollbackOnly()) {
            rollback(transaction);
            throw new RollbackException();
        }

        // Flush all pending writes
        if (!flushTables(transaction)) {
            cleanup(transaction);
            throw new RollbackException();
        }

        SyncCommitCallback cb = new SyncCommitCallback();
        TimerContext commitTimer = tsoclient.getMetrics().startTimer(Timers.COMMIT);
        try {
            tsoclient.commit(transaction.getStartTimestamp(), transaction.getRows(), cb);
            cb.await();
        } catch (Exception e) {
            throw new TransactionException("Could not commit", e);
        } finally {
            commitTimer.stop();
        }
        if (cb.getException() != null) {
            throw new TransactionException("Error committing", cb.getException());
        }

        if (LOG.isTraceEnabled()) {
            LOG.trace("doneCommit " + transaction.getStartTimestamp() + " TS_c: " + cb.getCommitTimestamp()
                    + " Success: " + (cb.getResult() == TSOClient.Result.OK));
        }

        if (cb.getResult() == TSOClient.Result.ABORTED) {
            cleanup(transaction);
            throw new RollbackException();
        }
        transaction.setCommitTimestamp(cb.getCommitTimestamp());
    } 
                            #location 21 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public void commit(Transaction transaction) throws RollbackException, TransactionException {
        if (LOG.isTraceEnabled()) {
            LOG.trace("commit " + transaction);
        }
        if (transaction.getStatus() != Status.RUNNING) {
            throw new IllegalArgumentException("Transaction has already been " + transaction.getStatus());
        }

        // Check rollbackOnly status
        if (transaction.isRollbackOnly()) {
            rollback(transaction);
            throw new RollbackException();
        }

        // Flush all pending writes
        if (!flushTables(transaction)) {
            cleanup(transaction);
            throw new RollbackException();
        }

        SyncCommitCallback cb = new SyncCommitCallback();
        TimerContext commitTimer = tsoclient.getMetrics().startTimer(Timers.COMMIT);
        try {
            tsoclient.commit(transaction.getStartTimestamp(), transaction.getRows(), cb);
            cb.await();
        } catch (Exception e) {
            throw new TransactionException("Could not commit", e);
        } finally {
            commitTimer.stop();
        }
        if (cb.getException() != null) {
            throw new TransactionException("Error committing", cb.getException());
        }

        if (LOG.isTraceEnabled()) {
            LOG.trace("doneCommit " + transaction.getStartTimestamp() + " TS_c: " + cb.getCommitTimestamp()
                    + " Success: " + (cb.getResult() == TSOClient.Result.OK));
        }

        if (cb.getResult() == TSOClient.Result.ABORTED) {
            cleanup(transaction);
            throw new RollbackException();
        }
        transaction.setStatus(Status.COMMITTED);
        transaction.setCommitTimestamp(cb.getCommitTimestamp());
    }