Program: 79975
Project: 79975
Buggy source:
/** 
 * Set the current value of an ANSI/ISO sequence. This method does not perform any sanity checking but assumes that the caller knows what they are doing. If the old value on disk is not what we expect it to be, then we are in a race with another session. They won and we don't update the value on disk. However, if the old value is null, that is a signal to us that we should update the value on disk anyway.
 * @param tc			Transaction Controller to use.
 * @param rowLocation Row in SYSSEQUENCES to update.
 * @param wait True if we should wait for locks
 * @param oldValue What we expect to find in the CURRENTVALUE column.
 * @param newValue What to stuff into the CURRENTVALUE column.
 * @return Returns true if the value was successfully updated, false if we lost a race with another session.
 * @exception StandardException thrown on failure.
 */
boolean updateCurrentSequenceValue(TransactionController tc,RowLocation rowLocation,boolean wait,Long oldValue,Long newValue) throws StandardException {
  int columnNum=SYSSEQUENCESRowFactory.SYSSEQUENCES_CURRENT_VALUE;
  FormatableBitSet columnToUpdate=new FormatableBitSet(SYSSEQUENCESRowFactory.SYSSEQUENCES_COLUMN_COUNT);
  TabInfoImpl ti=getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
  ConglomerateController heapCC=null;
  SYSSEQUENCESRowFactory rf=(SYSSEQUENCESRowFactory)ti.getCatalogRowFactory();
  ExecRow row=rf.makeEmptyRow();
  columnToUpdate.set(columnNum - 1);
  try {
    heapCC=tc.openConglomerate(ti.getHeapConglomerate(),false,(TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),TransactionController.MODE_RECORD,TransactionController.ISOLATION_REPEATABLE_READ);
    boolean baseRowExists=heapCC.fetch(rowLocation,row.getRowArray(),columnToUpdate,wait);
    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(baseRowExists,"String_Node_Str");
    }
    NumberDataValue oldValueOnDisk=(NumberDataValue)row.getColumn(columnNum);
    SQLLongint expectedOldValue;
    if (oldValue == null) {
      expectedOldValue=new SQLLongint();
    }
 else {
      expectedOldValue=new SQLLongint(oldValue.longValue());
    }
    if ((oldValue == null) || (expectedOldValue.compare(oldValueOnDisk) == 0)) {
      SQLLongint newValueOnDisk;
      if (newValue == null) {
        newValueOnDisk=new SQLLongint();
      }
 else {
        newValueOnDisk=new SQLLongint(newValue.longValue());
      }
      row.setColumn(columnNum,newValueOnDisk);
      heapCC.replace(rowLocation,row.getRowArray(),columnToUpdate);
      return true;
    }
 else {
      return false;
    }
  }
  finally {
    if (heapCC != null) {
      heapCC.close();
    }
  }
}

Fixed version (ground truth):
/** 
 * Set the current value of an ANSI/ISO sequence. This method does not perform any sanity checking but assumes that the caller knows what they are doing. If the old value on disk is not what we expect it to be, then we are in a race with another session. They won and we don't update the value on disk. However, if the old value is null, that is a signal to us that we should update the value on disk anyway.
 * @param tc			Transaction Controller to use.
 * @param rowLocation Row in SYSSEQUENCES to update.
 * @param wait True if we should wait for locks
 * @param oldValue What we expect to find in the CURRENTVALUE column.
 * @param newValue What to stuff into the CURRENTVALUE column.
 * @return Returns true if the value was successfully updated, false if we lost a race with another session.
 * @exception StandardException thrown on failure.
 */
boolean updateCurrentSequenceValue(TransactionController tc,RowLocation rowLocation,boolean wait,Long oldValue,Long newValue) throws StandardException {
  int columnNum=SYSSEQUENCESRowFactory.SYSSEQUENCES_CURRENT_VALUE;
  FormatableBitSet columnToUpdate=new FormatableBitSet(SYSSEQUENCESRowFactory.SYSSEQUENCES_COLUMN_COUNT);
  TabInfoImpl ti=getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
  ConglomerateController heapCC=null;
  SYSSEQUENCESRowFactory rf=(SYSSEQUENCESRowFactory)ti.getCatalogRowFactory();
  ExecRow row=rf.makeEmptyRow();
  columnToUpdate.set(columnNum - 1);
  try {
    heapCC=tc.openConglomerate(ti.getHeapConglomerate(),false,(TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),TransactionController.MODE_RECORD,TransactionController.ISOLATION_REPEATABLE_READ);
    boolean baseRowExists=heapCC.fetch(rowLocation,row.getRowArray(),columnToUpdate,wait);
    if (!baseRowExists) {
      return false;
    }
    NumberDataValue oldValueOnDisk=(NumberDataValue)row.getColumn(columnNum);
    SQLLongint expectedOldValue;
    if (oldValue == null) {
      expectedOldValue=new SQLLongint();
    }
 else {
      expectedOldValue=new SQLLongint(oldValue.longValue());
    }
    if ((oldValue == null) || (expectedOldValue.compare(oldValueOnDisk) == 0)) {
      SQLLongint newValueOnDisk;
      if (newValue == null) {
        newValueOnDisk=new SQLLongint();
      }
 else {
        newValueOnDisk=new SQLLongint(newValue.longValue());
      }
      row.setColumn(columnNum,newValueOnDisk);
      heapCC.replace(rowLocation,row.getRowArray(),columnToUpdate);
      return true;
    }
 else {
      return false;
    }
  }
  finally {
    if (heapCC != null) {
      heapCC.close();
    }
  }
}