Program: 16191
Project: 16191
Buggy source:
private synchronized void open(int traceLevelFile,int traceLevelSystemOut) throws SQLException {
  if (persistent) {
    if (SysProperties.PAGE_STORE) {
      String pageFileName=databaseName + Constants.SUFFIX_PAGE_FILE;
      if (FileUtils.exists(pageFileName) && FileUtils.isReadOnly(pageFileName)) {
        readOnly=true;
      }
    }
    String dataFileName=databaseName + Constants.SUFFIX_DATA_FILE;
    if (FileUtils.exists(dataFileName)) {
      readOnly=readOnly | FileUtils.isReadOnly(dataFileName);
    }
    if (readOnly) {
      traceSystem=new TraceSystem(null,false);
    }
 else {
      traceSystem=new TraceSystem(databaseName + Constants.SUFFIX_TRACE_FILE,true);
    }
    traceSystem.setLevelFile(traceLevelFile);
    traceSystem.setLevelSystemOut(traceLevelSystemOut);
    traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName + "String_Node_Str"+ Constants.BUILD_ID+ "String_Node_Str");
    if (autoServerMode) {
      if (readOnly || fileLockMethod == FileLock.LOCK_NO) {
        throw Message.getUnsupportedException("String_Node_Str");
      }
    }
    if (!readOnly && fileLockMethod != FileLock.LOCK_NO) {
      lock=new FileLock(traceSystem,databaseName + Constants.SUFFIX_LOCK_FILE,Constants.LOCK_SLEEP);
      lock.lock(fileLockMethod);
      if (autoServerMode) {
        startServer(lock.getUniqueId());
      }
    }
    isReconnectNeeded();
    beforeWriting();
    if (SysProperties.PAGE_STORE) {
      starting=true;
      getPageStore();
      starting=false;
    }
    if (FileUtils.exists(dataFileName)) {
      lobFilesInDirectories&=!ValueLob.existsLobFile(getDatabasePath());
      lobFilesInDirectories|=FileUtils.exists(databaseName + Constants.SUFFIX_LOBS_DIRECTORY);
    }
    dummy=DataPage.create(this,0);
    deleteOldTempFiles();
    log=new LogSystem(this,databaseName,readOnly,accessModeLog,pageStore);
    if (pageStore == null) {
      openFileData();
      log.open();
      openFileIndex();
      log.recover();
      fileData.init();
      try {
        fileIndex.init();
      }
 catch (      Exception e) {
        if (recovery) {
          traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
          ArrayList list=new ArrayList(storageMap.values());
          for (int i=0; i < list.size(); i++) {
            Storage s=(Storage)list.get(i);
            if (s.getDiskFile() == fileIndex) {
              removeStorage(s.getId(),fileIndex);
            }
          }
          fileIndex.delete();
          openFileIndex();
        }
 else {
          throw Message.convert(e);
        }
      }
    }
    reserveLobFileObjectIds();
    writer=WriterThread.create(this,writeDelay);
  }
 else {
    traceSystem=new TraceSystem(null,false);
    log=new LogSystem(null,null,false,null,null);
  }
  systemUser=new User(this,0,Constants.DBA_NAME,true);
  mainSchema=new Schema(this,0,Constants.SCHEMA_MAIN,systemUser,true);
  infoSchema=new Schema(this,-1,Constants.SCHEMA_INFORMATION,systemUser,true);
  schemas.put(mainSchema.getName(),mainSchema);
  schemas.put(infoSchema.getName(),infoSchema);
  publicRole=new Role(this,0,Constants.PUBLIC_ROLE_NAME,true);
  roles.put(Constants.PUBLIC_ROLE_NAME,publicRole);
  systemUser.setAdmin(true);
  systemSession=new Session(this,systemUser,++nextSessionId);
  ObjectArray cols=new ObjectArray();
  Column columnId=new Column("String_Node_Str",Value.INT);
  columnId.setNullable(false);
  cols.add(columnId);
  cols.add(new Column("String_Node_Str",Value.INT));
  cols.add(new Column("String_Node_Str",Value.INT));
  cols.add(new Column("String_Node_Str",Value.STRING));
  int headPos=0;
  if (pageStore != null) {
    headPos=pageStore.getSystemTableHeadPos();
  }
  meta=mainSchema.createTable("String_Node_Str",0,cols,persistent,persistent,false,headPos);
  IndexColumn[] pkCols=IndexColumn.wrap(new Column[]{columnId});
  metaIdIndex=meta.addIndex(systemSession,"String_Node_Str",0,pkCols,IndexType.createPrimaryKey(false,false),Index.EMPTY_HEAD,null);
  objectIds.set(0);
  for (int i=0; i < MetaTable.getMetaTableTypeCount(); i++) {
    addMetaData(i);
  }
  starting=true;
  Cursor cursor=metaIdIndex.find(systemSession,null,null);
  ObjectArray records=new ObjectArray();
  while (cursor.next()) {
    MetaRecord rec=new MetaRecord(cursor.get());
    objectIds.set(rec.getId());
    records.add(rec);
  }
  MetaRecord.sort(records);
  for (int i=0; i < records.size(); i++) {
    MetaRecord rec=(MetaRecord)records.get(i);
    rec.execute(this,systemSession,eventListener);
  }
  recompileInvalidViews(systemSession);
  starting=false;
  addDefaultSetting(systemSession,SetTypes.DEFAULT_LOCK_TIMEOUT,null,Constants.INITIAL_LOCK_TIMEOUT);
  addDefaultSetting(systemSession,SetTypes.DEFAULT_TABLE_TYPE,null,Constants.DEFAULT_TABLE_TYPE);
  addDefaultSetting(systemSession,SetTypes.CACHE_SIZE,null,SysProperties.CACHE_SIZE_DEFAULT);
  addDefaultSetting(systemSession,SetTypes.CLUSTER,Constants.CLUSTERING_DISABLED,0);
  addDefaultSetting(systemSession,SetTypes.WRITE_DELAY,null,Constants.DEFAULT_WRITE_DELAY);
  addDefaultSetting(systemSession,SetTypes.CREATE_BUILD,null,Constants.BUILD_ID);
  if (!readOnly) {
    removeUnusedStorages(systemSession);
  }
  systemSession.commit(true);
  traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName);
  afterWriting();
}

Fixed version (ground truth):
private synchronized void open(int traceLevelFile,int traceLevelSystemOut) throws SQLException {
  if (persistent) {
    if (SysProperties.PAGE_STORE) {
      String pageFileName=databaseName + Constants.SUFFIX_PAGE_FILE;
      if (FileUtils.exists(pageFileName) && FileUtils.isReadOnly(pageFileName)) {
        readOnly=true;
      }
    }
    String dataFileName=databaseName + Constants.SUFFIX_DATA_FILE;
    if (FileUtils.exists(dataFileName)) {
      readOnly=readOnly | FileUtils.isReadOnly(dataFileName);
    }
    if (readOnly) {
      traceSystem=new TraceSystem(null,false);
    }
 else {
      traceSystem=new TraceSystem(databaseName + Constants.SUFFIX_TRACE_FILE,true);
    }
    traceSystem.setLevelFile(traceLevelFile);
    traceSystem.setLevelSystemOut(traceLevelSystemOut);
    traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName + "String_Node_Str"+ Constants.BUILD_ID+ "String_Node_Str");
    if (autoServerMode) {
      if (readOnly || fileLockMethod == FileLock.LOCK_NO) {
        throw Message.getUnsupportedException("String_Node_Str");
      }
    }
    if (!readOnly && fileLockMethod != FileLock.LOCK_NO) {
      lock=new FileLock(traceSystem,databaseName + Constants.SUFFIX_LOCK_FILE,Constants.LOCK_SLEEP);
      lock.lock(fileLockMethod);
      if (autoServerMode) {
        startServer(lock.getUniqueId());
      }
    }
    isReconnectNeeded();
    while (!beforeWriting()) {
    }
    if (SysProperties.PAGE_STORE) {
      starting=true;
      getPageStore();
      starting=false;
    }
    if (FileUtils.exists(dataFileName)) {
      lobFilesInDirectories&=!ValueLob.existsLobFile(getDatabasePath());
      lobFilesInDirectories|=FileUtils.exists(databaseName + Constants.SUFFIX_LOBS_DIRECTORY);
    }
    dummy=DataPage.create(this,0);
    deleteOldTempFiles();
    log=new LogSystem(this,databaseName,readOnly,accessModeLog,pageStore);
    if (pageStore == null) {
      openFileData();
      log.open();
      openFileIndex();
      log.recover();
      fileData.init();
      try {
        fileIndex.init();
      }
 catch (      Exception e) {
        if (recovery) {
          traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
          ArrayList list=new ArrayList(storageMap.values());
          for (int i=0; i < list.size(); i++) {
            Storage s=(Storage)list.get(i);
            if (s.getDiskFile() == fileIndex) {
              removeStorage(s.getId(),fileIndex);
            }
          }
          fileIndex.delete();
          openFileIndex();
        }
 else {
          throw Message.convert(e);
        }
      }
    }
    reserveLobFileObjectIds();
    writer=WriterThread.create(this,writeDelay);
  }
 else {
    traceSystem=new TraceSystem(null,false);
    log=new LogSystem(null,null,false,null,null);
  }
  systemUser=new User(this,0,Constants.DBA_NAME,true);
  mainSchema=new Schema(this,0,Constants.SCHEMA_MAIN,systemUser,true);
  infoSchema=new Schema(this,-1,Constants.SCHEMA_INFORMATION,systemUser,true);
  schemas.put(mainSchema.getName(),mainSchema);
  schemas.put(infoSchema.getName(),infoSchema);
  publicRole=new Role(this,0,Constants.PUBLIC_ROLE_NAME,true);
  roles.put(Constants.PUBLIC_ROLE_NAME,publicRole);
  systemUser.setAdmin(true);
  systemSession=new Session(this,systemUser,++nextSessionId);
  ObjectArray cols=new ObjectArray();
  Column columnId=new Column("String_Node_Str",Value.INT);
  columnId.setNullable(false);
  cols.add(columnId);
  cols.add(new Column("String_Node_Str",Value.INT));
  cols.add(new Column("String_Node_Str",Value.INT));
  cols.add(new Column("String_Node_Str",Value.STRING));
  int headPos=0;
  if (pageStore != null) {
    headPos=pageStore.getSystemTableHeadPos();
  }
  meta=mainSchema.createTable("String_Node_Str",0,cols,persistent,persistent,false,headPos);
  IndexColumn[] pkCols=IndexColumn.wrap(new Column[]{columnId});
  metaIdIndex=meta.addIndex(systemSession,"String_Node_Str",0,pkCols,IndexType.createPrimaryKey(false,false),Index.EMPTY_HEAD,null);
  objectIds.set(0);
  for (int i=0; i < MetaTable.getMetaTableTypeCount(); i++) {
    addMetaData(i);
  }
  starting=true;
  Cursor cursor=metaIdIndex.find(systemSession,null,null);
  ObjectArray records=new ObjectArray();
  while (cursor.next()) {
    MetaRecord rec=new MetaRecord(cursor.get());
    objectIds.set(rec.getId());
    records.add(rec);
  }
  MetaRecord.sort(records);
  for (int i=0; i < records.size(); i++) {
    MetaRecord rec=(MetaRecord)records.get(i);
    rec.execute(this,systemSession,eventListener);
  }
  recompileInvalidViews(systemSession);
  starting=false;
  addDefaultSetting(systemSession,SetTypes.DEFAULT_LOCK_TIMEOUT,null,Constants.INITIAL_LOCK_TIMEOUT);
  addDefaultSetting(systemSession,SetTypes.DEFAULT_TABLE_TYPE,null,Constants.DEFAULT_TABLE_TYPE);
  addDefaultSetting(systemSession,SetTypes.CACHE_SIZE,null,SysProperties.CACHE_SIZE_DEFAULT);
  addDefaultSetting(systemSession,SetTypes.CLUSTER,Constants.CLUSTERING_DISABLED,0);
  addDefaultSetting(systemSession,SetTypes.WRITE_DELAY,null,Constants.DEFAULT_WRITE_DELAY);
  addDefaultSetting(systemSession,SetTypes.CREATE_BUILD,null,Constants.BUILD_ID);
  if (!readOnly) {
    removeUnusedStorages(systemSession);
  }
  systemSession.commit(true);
  traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName);
}