Program: 15849
Project: 15849
Buggy source:
/** 
 * Close all open files and unlock the database.
 * @param flush whether writing is allowed
 */
private synchronized void closeOpenFilesAndUnlock(boolean flush){
  stopWriter();
  if (pageStore != null && mvStore == null) {
    if (flush) {
      try {
        pageStore.checkpoint();
        if (!readOnly) {
          lockMeta(pageStore.getPageStoreSession());
          pageStore.compact(compactMode);
        }
      }
 catch (      DbException e) {
        if (SysProperties.CHECK2) {
          int code=e.getErrorCode();
          if (code != ErrorCode.DATABASE_IS_CLOSED && code != ErrorCode.LOCK_TIMEOUT_1 && code != ErrorCode.IO_EXCEPTION_2) {
            e.printStackTrace();
          }
        }
        trace.error(e,"String_Node_Str");
      }
catch (      Throwable t) {
        if (SysProperties.CHECK2) {
          t.printStackTrace();
        }
        trace.error(t,"String_Node_Str");
      }
    }
  }
  reconnectModified(false);
  if (mvStore != null) {
    if (!readOnly && compactMode != 0) {
      mvStore.compactFile(dbSettings.maxCompactTime);
    }
    mvStore.close(dbSettings.maxCompactTime);
  }
  closeFiles();
  if (persistent && lock == null && fileLockMethod != FileLock.LOCK_NO && fileLockMethod != FileLock.LOCK_FS) {
    return;
  }
  if (persistent) {
    deleteOldTempFiles();
  }
  if (systemSession != null) {
    systemSession.close();
    systemSession=null;
  }
  if (lobSession != null) {
    lobSession.close();
    lobSession=null;
  }
  if (lock != null) {
    if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
      if (lock.load().containsKey("String_Node_Str")) {
        try {
          Thread.sleep((int)(reconnectCheckDelay * 1.1));
        }
 catch (        InterruptedException e) {
          trace.error(e,"String_Node_Str");
        }
      }
    }
    lock.unlock();
    lock=null;
  }
}

Fixed version (ground truth):
/** 
 * Close all open files and unlock the database.
 * @param flush whether writing is allowed
 */
private synchronized void closeOpenFilesAndUnlock(boolean flush){
  stopWriter();
  if (pageStore != null) {
    if (flush) {
      try {
        pageStore.checkpoint();
        if (!readOnly) {
          lockMeta(pageStore.getPageStoreSession());
          pageStore.compact(compactMode);
        }
      }
 catch (      DbException e) {
        if (SysProperties.CHECK2) {
          int code=e.getErrorCode();
          if (code != ErrorCode.DATABASE_IS_CLOSED && code != ErrorCode.LOCK_TIMEOUT_1 && code != ErrorCode.IO_EXCEPTION_2) {
            e.printStackTrace();
          }
        }
        trace.error(e,"String_Node_Str");
      }
catch (      Throwable t) {
        if (SysProperties.CHECK2) {
          t.printStackTrace();
        }
        trace.error(t,"String_Node_Str");
      }
    }
  }
  reconnectModified(false);
  if (mvStore != null) {
    if (!readOnly && compactMode != 0) {
      mvStore.compactFile(dbSettings.maxCompactTime);
    }
    mvStore.close(dbSettings.maxCompactTime);
  }
  closeFiles();
  if (persistent && lock == null && fileLockMethod != FileLock.LOCK_NO && fileLockMethod != FileLock.LOCK_FS) {
    return;
  }
  if (persistent) {
    deleteOldTempFiles();
  }
  if (systemSession != null) {
    systemSession.close();
    systemSession=null;
  }
  if (lobSession != null) {
    lobSession.close();
    lobSession=null;
  }
  if (lock != null) {
    if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
      if (lock.load().containsKey("String_Node_Str")) {
        try {
          Thread.sleep((int)(reconnectCheckDelay * 1.1));
        }
 catch (        InterruptedException e) {
          trace.error(e,"String_Node_Str");
        }
      }
    }
    lock.unlock();
    lock=null;
  }
}