Program: 79982
Project: 79982
Buggy source:
/** 
 * Bind this CursorNode.  This means looking up tables and columns and getting their types, and figuring out the result types of all expressions, as well as doing view resolution, permissions checking, etc. It also includes determining whether an UNSPECIFIED cursor is updatable or not, and verifying that an UPDATE cursor actually is.
 * @exception StandardException		Thrown on error
 */
@Override public void bindStatement() throws StandardException {
  boolean wasSkippingTypePrivileges=getCompilerContext().skipTypePrivileges(true);
  DataDictionary dataDictionary;
  dataDictionary=getDataDictionary();
  checkIndexStats=(dataDictionary.getIndexStatsRefresher(true) != null);
  if (orderByList != null) {
    orderByList.pullUpOrderByColumns(resultSet);
  }
  getCompilerContext().pushCurrentPrivType(getPrivType());
  try {
    FromList fromList=new FromList(getOptimizerFactory().doJoinOrderOptimization(),getContextManager());
    resultSet.rejectParameters();
    super.bind(dataDictionary);
    resultSet.bindResultColumns(fromList);
    resultSet.bindUntypedNullsToResultColumns(null);
    resultSet.rejectXMLValues();
    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(fromList.size() == 0,"String_Node_Str" + fromList.size() + "String_Node_Str");
    }
  }
  finally {
    getCompilerContext().popCurrentPrivType();
  }
  collectTablesWithPossiblyStaleStats();
  if (orderByList != null) {
    orderByList.bindOrderByColumns(resultSet);
  }
  bindOffsetFetch(offset,fetchFirst);
  if (updateMode == UPDATE) {
    int checkedUpdateMode;
    checkedUpdateMode=determineUpdateMode(dataDictionary);
    if (SanityManager.DEBUG)     SanityManager.DEBUG("String_Node_Str","String_Node_Str" + updateMode + "String_Node_Str"+ checkedUpdateMode);
    if (updateMode != checkedUpdateMode)     throw StandardException.newException(SQLState.LANG_STMT_NOT_UPDATABLE);
  }
  if (updateMode == UNSPECIFIED) {
    if (getLanguageConnectionContext().getStatementContext().isForReadOnly()) {
      updateMode=READ_ONLY;
    }
 else {
      updateMode=determineUpdateMode(dataDictionary);
    }
  }
  if (updateMode == READ_ONLY) {
    updatableColumns=null;
  }
  if (updateMode == UPDATE) {
    bindUpdateColumns(updateTable);
    if (updateTable != null) {
      updateTable.markUpdatableByCursor(updatableColumns);
      resultSet.getResultColumns().markColumnsInSelectListUpdatableByCursor(updatableColumns);
    }
  }
  resultSet.renameGeneratedResultNames();
  if (getLanguageConnectionContext().checkIfAnyDeclaredGlobalTempTablesForThisConnection()) {
    ArrayList<String> sessionSchemaTableNames=getSessionSchemaTableNamesForCursor();
    if (sessionSchemaTableNames != null)     indexOfSessionTableNamesInSavedObjects=getCompilerContext().addSavedObject(sessionSchemaTableNames);
  }
  getCompilerContext().skipTypePrivileges(wasSkippingTypePrivileges);
}

Fixed version (ground truth):
/** 
 * Bind this CursorNode.  This means looking up tables and columns and getting their types, and figuring out the result types of all expressions, as well as doing view resolution, permissions checking, etc. It also includes determining whether an UNSPECIFIED cursor is updatable or not, and verifying that an UPDATE cursor actually is.
 * @exception StandardException		Thrown on error
 */
@Override public void bindStatement() throws StandardException {
  boolean wasSkippingTypePrivileges=getCompilerContext().skipTypePrivileges(true);
  DataDictionary dataDictionary;
  dataDictionary=getDataDictionary();
  checkIndexStats=(dataDictionary.getIndexStatsRefresher(true) != null);
  if (orderByList != null) {
    orderByList.pullUpOrderByColumns(resultSet);
  }
  getCompilerContext().pushCurrentPrivType(getPrivType());
  try {
    FromList fromList=new FromList(getOptimizerFactory().doJoinOrderOptimization(),getContextManager());
    resultSet.rejectParameters();
    super.bind(dataDictionary);
    resultSet.bindResultColumns(fromList);
    resultSet.bindUntypedNullsToResultColumns(null);
    if (!forMergeStatement) {
      resultSet.rejectXMLValues();
    }
    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(fromList.size() == 0,"String_Node_Str" + fromList.size() + "String_Node_Str");
    }
  }
  finally {
    getCompilerContext().popCurrentPrivType();
  }
  collectTablesWithPossiblyStaleStats();
  if (orderByList != null) {
    orderByList.bindOrderByColumns(resultSet);
  }
  bindOffsetFetch(offset,fetchFirst);
  if (updateMode == UPDATE) {
    int checkedUpdateMode;
    checkedUpdateMode=determineUpdateMode(dataDictionary);
    if (SanityManager.DEBUG)     SanityManager.DEBUG("String_Node_Str","String_Node_Str" + updateMode + "String_Node_Str"+ checkedUpdateMode);
    if (updateMode != checkedUpdateMode)     throw StandardException.newException(SQLState.LANG_STMT_NOT_UPDATABLE);
  }
  if (updateMode == UNSPECIFIED) {
    if (getLanguageConnectionContext().getStatementContext().isForReadOnly()) {
      updateMode=READ_ONLY;
    }
 else {
      updateMode=determineUpdateMode(dataDictionary);
    }
  }
  if (updateMode == READ_ONLY) {
    updatableColumns=null;
  }
  if (updateMode == UPDATE) {
    bindUpdateColumns(updateTable);
    if (updateTable != null) {
      updateTable.markUpdatableByCursor(updatableColumns);
      resultSet.getResultColumns().markColumnsInSelectListUpdatableByCursor(updatableColumns);
    }
  }
  resultSet.renameGeneratedResultNames();
  if (getLanguageConnectionContext().checkIfAnyDeclaredGlobalTempTablesForThisConnection()) {
    ArrayList<String> sessionSchemaTableNames=getSessionSchemaTableNamesForCursor();
    if (sessionSchemaTableNames != null)     indexOfSessionTableNamesInSavedObjects=getCompilerContext().addSavedObject(sessionSchemaTableNames);
  }
  getCompilerContext().skipTypePrivileges(wasSkippingTypePrivileges);
}