Program: 16174
Project: 16174
Buggy source:
private synchronized void open(int traceLevelFile,int traceLevelSystemOut) throws SQLException {
  if (persistent) {
    String pageFileName=databaseName + Constants.SUFFIX_PAGE_FILE;
    boolean exists=FileUtils.exists(pageFileName);
    if (exists) {
      usePageStore=true;
    }
    if (usePageStore) {
      if (exists && FileUtils.isReadOnly(pageFileName)) {
        readOnly=true;
      }
    }
 else {
      String dataFileName=databaseName + Constants.SUFFIX_DATA_FILE;
      exists=FileUtils.exists(dataFileName);
      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 (exists) {
      lobFilesInDirectories&=!ValueLob.existsLobFile(getDatabasePath());
      lobFilesInDirectories|=FileUtils.exists(databaseName + Constants.SUFFIX_LOBS_DIRECTORY);
    }
    dummy=DataPage.create(this,0);
    deleteOldTempFiles();
    if (usePageStore) {
      starting=true;
      getPageStore();
      starting=false;
    }
    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);
          for (          Storage s : New.arrayList(storageMap.values())) {
            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<Column> cols=ObjectArray.newInstance();
  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,systemSession);
  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<MetaRecord> records=ObjectArray.newInstance();
  while (cursor.next()) {
    MetaRecord rec=new MetaRecord(cursor.get());
    objectIds.set(rec.getId());
    records.add(rec);
  }
  MetaRecord.sort(records);
  for (  MetaRecord rec : records) {
    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);
}

Fixed version (ground truth):
private synchronized void open(int traceLevelFile,int traceLevelSystemOut) throws SQLException {
  if (persistent) {
    String pageFileName=databaseName + Constants.SUFFIX_PAGE_FILE;
    boolean exists=FileUtils.exists(pageFileName);
    if (exists) {
      usePageStore=true;
    }
    if (usePageStore) {
      if (exists && FileUtils.isReadOnly(pageFileName)) {
        readOnly=true;
      }
    }
 else {
      String dataFileName=databaseName + Constants.SUFFIX_DATA_FILE;
      exists=FileUtils.exists(dataFileName);
      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());
      }
    }
    while (isReconnectNeeded() && !beforeWriting()) {
    }
    if (exists) {
      lobFilesInDirectories&=!ValueLob.existsLobFile(getDatabasePath());
      lobFilesInDirectories|=FileUtils.exists(databaseName + Constants.SUFFIX_LOBS_DIRECTORY);
    }
    dummy=DataPage.create(this,0);
    deleteOldTempFiles();
    if (usePageStore) {
      starting=true;
      getPageStore();
      starting=false;
    }
    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);
          for (          Storage s : New.arrayList(storageMap.values())) {
            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<Column> cols=ObjectArray.newInstance();
  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,systemSession);
  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<MetaRecord> records=ObjectArray.newInstance();
  while (cursor.next()) {
    MetaRecord rec=new MetaRecord(cursor.get());
    objectIds.set(rec.getId());
    records.add(rec);
  }
  MetaRecord.sort(records);
  for (  MetaRecord rec : records) {
    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);
}