Program: 80041
Project: 80041
Buggy source:
/** 
 * Switch to the next log file if possible. <P>MT - log factory is single threaded thru a log file switch, the log is frozen for the duration of the switch
 */
public void switchLogFile() throws StandardException {
  boolean switchedOver=false;
synchronized (this) {
    while (logBeingFlushed | isFrozen) {
      try {
        wait();
      }
 catch (      InterruptedException ie) {
        InterruptStatus.setInterrupted();
      }
    }
    if (endPosition == LOG_FILE_HEADER_SIZE) {
      if (SanityManager.DEBUG) {
        Monitor.logMessage("String_Node_Str" + logFileNumber + "String_Node_Str");
      }
      return;
    }
    StorageFile newLogFile=getLogFileName(logFileNumber + 1);
    if (logFileNumber + 1 >= maxLogFileNumber) {
      throw StandardException.newException(SQLState.LOG_EXCEED_MAX_LOG_FILE_NUMBER,new Long(maxLogFileNumber));
    }
    StorageRandomAccessFile newLog=null;
    try {
      if (privExists(newLogFile) && !privDelete(newLogFile)) {
        logErrMsg(MessageService.getTextMessage(MessageId.LOG_NEW_LOGFILE_EXIST,newLogFile.getPath()));
        return;
      }
      try {
        newLog=privRandomAccessFile(newLogFile,"String_Node_Str");
      }
 catch (      IOException ioe) {
        newLog=null;
      }
      if (newLog == null || !privCanWrite(newLogFile)) {
        if (newLog != null)         newLog.close();
        newLog=null;
        return;
      }
      if (initLogFile(newLog,logFileNumber + 1,LogCounter.makeLogInstantAsLong(logFileNumber,endPosition))) {
        switchedOver=true;
        logOut.writeEndMarker(0);
        endPosition+=4;
        inLogSwitch=true;
        flush(logFileNumber,endPosition);
        if (SanityManager.DEBUG) {
          if (SanityManager.DEBUG_ON(TEST_SWITCH_LOG_FAIL2))           throw new IOException("String_Node_Str");
        }
        logOut.close();
        logWrittenFromLastCheckPoint+=endPosition;
        endPosition=newLog.getFilePointer();
        lastFlush=endPosition;
        if (isWriteSynced) {
          preAllocateNewLogFile(newLog);
          newLog.close();
          newLog=openLogFileInWriteMode(newLogFile);
          newLog.seek(endPosition);
        }
        logOut=new LogAccessFile(this,newLog,logBufferSize);
        newLog=null;
        if (SanityManager.DEBUG) {
          if (endPosition != LOG_FILE_HEADER_SIZE)           SanityManager.THROWASSERT("String_Node_Str" + +endPosition);
        }
        logFileNumber++;
        if (SanityManager.DEBUG) {
          SanityManager.ASSERT(endPosition == LOG_FILE_HEADER_SIZE,"String_Node_Str");
        }
      }
 else {
        newLog.close();
        newLog=null;
        if (privExists(newLogFile))         privDelete(newLogFile);
        newLogFile=null;
        logErrMsg(MessageService.getTextMessage(MessageId.LOG_CANNOT_CREATE_NEW,newLogFile.getPath()));
      }
    }
 catch (    IOException ioe) {
      inLogSwitch=false;
      logErrMsg(MessageService.getTextMessage(MessageId.LOG_CANNOT_CREATE_NEW_DUETO,newLogFile.getPath(),ioe.toString()));
      try {
        if (newLog != null) {
          newLog.close();
          newLog=null;
        }
      }
 catch (      IOException ioe2) {
      }
      if (newLogFile != null && privExists(newLogFile)) {
        privDelete(newLogFile);
        newLogFile=null;
      }
      if (switchedOver) {
        logOut=null;
        throw markCorrupt(StandardException.newException(SQLState.LOG_IO_ERROR,ioe));
      }
    }
    if (inReplicationSlaveMode) {
      allowedToReadFileNumber=logFileNumber - 1;
synchronized (slaveRecoveryMonitor) {
        slaveRecoveryMonitor.notify();
      }
    }
    inLogSwitch=false;
  }
}

Fixed version (ground truth):
/** 
 * Switch to the next log file if possible. <P>MT - log factory is single threaded thru a log file switch, the log is frozen for the duration of the switch
 */
public void switchLogFile() throws StandardException {
  boolean switchedOver=false;
synchronized (this) {
    while (logBeingFlushed | isFrozen) {
      try {
        wait();
      }
 catch (      InterruptedException ie) {
        InterruptStatus.setInterrupted();
      }
    }
    if (endPosition == LOG_FILE_HEADER_SIZE) {
      if (SanityManager.DEBUG) {
        Monitor.logMessage("String_Node_Str" + logFileNumber + "String_Node_Str");
      }
      return;
    }
    StorageFile newLogFile=getLogFileName(logFileNumber + 1);
    if (logFileNumber + 1 >= maxLogFileNumber) {
      throw StandardException.newException(SQLState.LOG_EXCEED_MAX_LOG_FILE_NUMBER,new Long(maxLogFileNumber));
    }
    StorageRandomAccessFile newLog=null;
    try {
      if (privExists(newLogFile) && !privDelete(newLogFile)) {
        logErrMsg(MessageService.getTextMessage(MessageId.LOG_NEW_LOGFILE_EXIST,newLogFile.getPath()));
        return;
      }
      try {
        newLog=privRandomAccessFile(newLogFile,"String_Node_Str");
      }
 catch (      IOException ioe) {
        newLog=null;
      }
      if (newLog == null || !privCanWrite(newLogFile)) {
        if (newLog != null)         newLog.close();
        newLog=null;
        return;
      }
      if (initLogFile(newLog,logFileNumber + 1,LogCounter.makeLogInstantAsLong(logFileNumber,endPosition))) {
        switchedOver=true;
        logOut.writeEndMarker(0);
        endPosition+=4;
        inLogSwitch=true;
        flush(logFileNumber,endPosition);
        if (SanityManager.DEBUG) {
          if (SanityManager.DEBUG_ON(TEST_SWITCH_LOG_FAIL2))           throw new IOException("String_Node_Str");
        }
        logOut.close();
        logWrittenFromLastCheckPoint+=endPosition;
        endPosition=newLog.getFilePointer();
        lastFlush=endPosition;
        if (isWriteSynced) {
          preAllocateNewLogFile(newLog);
          newLog.close();
          newLog=openLogFileInWriteMode(newLogFile);
          newLog.seek(endPosition);
        }
        logOut=new LogAccessFile(this,newLog,logBufferSize);
        newLog=null;
        if (SanityManager.DEBUG) {
          if (endPosition != LOG_FILE_HEADER_SIZE)           SanityManager.THROWASSERT("String_Node_Str" + +endPosition);
        }
        logFileNumber++;
        if (SanityManager.DEBUG) {
          SanityManager.ASSERT(endPosition == LOG_FILE_HEADER_SIZE,"String_Node_Str");
        }
      }
 else {
        newLog.close();
        newLog=null;
        if (privExists(newLogFile))         privDelete(newLogFile);
        logErrMsg(MessageService.getTextMessage(MessageId.LOG_CANNOT_CREATE_NEW,newLogFile.getPath()));
        newLogFile=null;
      }
    }
 catch (    IOException ioe) {
      inLogSwitch=false;
      logErrMsg(MessageService.getTextMessage(MessageId.LOG_CANNOT_CREATE_NEW_DUETO,newLogFile.getPath(),ioe.toString()));
      try {
        if (newLog != null) {
          newLog.close();
          newLog=null;
        }
      }
 catch (      IOException ioe2) {
      }
      if (newLogFile != null && privExists(newLogFile)) {
        privDelete(newLogFile);
        newLogFile=null;
      }
      if (switchedOver) {
        logOut=null;
        throw markCorrupt(StandardException.newException(SQLState.LOG_IO_ERROR,ioe));
      }
    }
    if (inReplicationSlaveMode) {
      allowedToReadFileNumber=logFileNumber - 1;
synchronized (slaveRecoveryMonitor) {
        slaveRecoveryMonitor.notify();
      }
    }
    inLogSwitch=false;
  }
}