Program: 15809
Project: 15809
Buggy source:
private synchronized void open(int traceLevelFile,int traceLevelSystemOut){
  if (persistent) {
    String dataFileName=databaseName + "String_Node_Str";
    boolean existsData=FileUtils.exists(dataFileName);
    String pageFileName=databaseName + Constants.SUFFIX_PAGE_FILE;
    String mvFileName=databaseName + Constants.SUFFIX_MV_FILE;
    boolean existsPage=FileUtils.exists(pageFileName);
    boolean existsMv=FileUtils.exists(mvFileName);
    if (existsData && (!existsPage && !existsMv)) {
      throw DbException.get(ErrorCode.FILE_VERSION_ERROR_1,"String_Node_Str" + dataFileName + "String_Node_Str"+ "String_Node_Str");
    }
    if (existsPage && !FileUtils.canWrite(pageFileName)) {
      readOnly=true;
    }
    if (existsMv && !FileUtils.canWrite(mvFileName)) {
      readOnly=true;
    }
    if (readOnly) {
      if (traceLevelFile >= TraceSystem.DEBUG) {
        String traceFile=Utils.getProperty("String_Node_Str","String_Node_Str") + "String_Node_Str" + "String_Node_Str"+ System.currentTimeMillis();
        traceSystem=new TraceSystem(traceFile + Constants.SUFFIX_TRACE_FILE);
      }
 else {
        traceSystem=new TraceSystem(null);
      }
    }
 else {
      traceSystem=new TraceSystem(databaseName + Constants.SUFFIX_TRACE_FILE);
    }
    traceSystem.setLevelFile(traceLevelFile);
    traceSystem.setLevelSystemOut(traceLevelSystemOut);
    trace=traceSystem.getTrace(Trace.DATABASE);
    trace.info("String_Node_Str",databaseName,Constants.BUILD_ID);
    if (autoServerMode) {
      if (readOnly || fileLockMethod == FileLock.LOCK_NO || fileLockMethod == FileLock.LOCK_SERIALIZED || fileLockMethod == FileLock.LOCK_FS || !persistent) {
        throw DbException.getUnsupportedException("String_Node_Str" + "String_Node_Str");
      }
    }
    String lockFileName=databaseName + Constants.SUFFIX_LOCK_FILE;
    if (readOnly) {
      if (FileUtils.exists(lockFileName)) {
        throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1,"String_Node_Str" + lockFileName);
      }
    }
    if (!readOnly && fileLockMethod != FileLock.LOCK_NO) {
      if (fileLockMethod != FileLock.LOCK_FS) {
        lock=new FileLock(traceSystem,lockFileName,Constants.LOCK_SLEEP);
        lock.lock(fileLockMethod);
        if (autoServerMode) {
          startServer(lock.getUniqueId());
        }
      }
    }
    if (SysProperties.MODIFY_ON_WRITE) {
      while (isReconnectNeeded()) {
      }
    }
 else {
      while (isReconnectNeeded() && !beforeWriting()) {
      }
    }
    deleteOldTempFiles();
    starting=true;
    if (SysProperties.MODIFY_ON_WRITE) {
      try {
        getPageStore();
      }
 catch (      DbException e) {
        if (e.getErrorCode() != ErrorCode.DATABASE_IS_READ_ONLY) {
          throw e;
        }
        pageStore=null;
        while (!beforeWriting()) {
        }
        getPageStore();
      }
    }
 else {
      getPageStore();
    }
    starting=false;
    if (mvStore == null) {
      writer=WriterThread.create(this,writeDelay);
    }
 else {
      setWriteDelay(writeDelay);
    }
  }
 else {
    if (autoServerMode) {
      throw DbException.getUnsupportedException("String_Node_Str");
    }
    traceSystem=new TraceSystem(null);
    trace=traceSystem.getTrace(Trace.DATABASE);
    getPageStore();
  }
  systemUser=new User(this,0,SYSTEM_USER_NAME,true);
  mainSchema=new Schema(this,0,Constants.SCHEMA_MAIN,systemUser,true);
  infoSchema=new Schema(this,-1,"String_Node_Str",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);
  lobSession=new Session(this,systemUser,++nextSessionId);
  CreateTableData data=new CreateTableData();
  ArrayList<Column> cols=data.columns;
  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));
  boolean create=true;
  if (pageStore != null) {
    create=pageStore.isNew();
  }
  data.tableName="String_Node_Str";
  data.id=0;
  data.temporary=false;
  data.persistData=persistent;
  data.persistIndexes=persistent;
  data.create=create;
  data.isHidden=true;
  data.session=systemSession;
  meta=mainSchema.createTable(data);
  IndexColumn[] pkCols=IndexColumn.wrap(new Column[]{columnId});
  metaIdIndex=meta.addIndex(systemSession,"String_Node_Str",0,pkCols,IndexType.createPrimaryKey(false,false),true,null);
  objectIds.set(0);
  starting=true;
  Cursor cursor=metaIdIndex.find(systemSession,null,null);
  ArrayList<MetaRecord> records=New.arrayList();
  while (cursor.next()) {
    MetaRecord rec=new MetaRecord(cursor.get());
    objectIds.set(rec.getId());
    records.add(rec);
  }
  Collections.sort(records);
  for (  MetaRecord rec : records) {
    rec.execute(this,systemSession,eventListener);
  }
  if (mvStore != null) {
    mvStore.initTransactions();
    mvStore.removeTemporaryMaps();
  }
  recompileInvalidViews(systemSession);
  starting=false;
  if (!readOnly) {
    String name=SetTypes.getTypeName(SetTypes.CREATE_BUILD);
    if (settings.get(name) == null) {
      Setting setting=new Setting(this,allocateObjectId(),name);
      setting.setIntValue(Constants.BUILD_ID);
      lockMeta(systemSession);
      addDatabaseObject(systemSession,setting);
    }
    if (pageStore != null) {
      BitField f=pageStore.getObjectIds();
      for (int i=0, len=f.length(); i < len; i++) {
        if (f.get(i) && !objectIds.get(i)) {
          trace.info("String_Node_Str" + i);
          objectIds.set(i);
        }
      }
    }
  }
  getLobStorage().init();
  systemSession.commit(true);
  trace.info("String_Node_Str",databaseName);
  if (checkpointAllowed > 0) {
    afterWriting();
  }
}

Fixed version (ground truth):
private synchronized void open(int traceLevelFile,int traceLevelSystemOut){
  if (persistent) {
    String dataFileName=databaseName + "String_Node_Str";
    boolean existsData=FileUtils.exists(dataFileName);
    String pageFileName=databaseName + Constants.SUFFIX_PAGE_FILE;
    String mvFileName=databaseName + Constants.SUFFIX_MV_FILE;
    boolean existsPage=FileUtils.exists(pageFileName);
    boolean existsMv=FileUtils.exists(mvFileName);
    if (existsData && (!existsPage && !existsMv)) {
      throw DbException.get(ErrorCode.FILE_VERSION_ERROR_1,"String_Node_Str" + dataFileName + "String_Node_Str"+ "String_Node_Str");
    }
    if (existsPage && !FileUtils.canWrite(pageFileName)) {
      readOnly=true;
    }
    if (existsMv && !FileUtils.canWrite(mvFileName)) {
      readOnly=true;
    }
    if (readOnly) {
      if (traceLevelFile >= TraceSystem.DEBUG) {
        String traceFile=Utils.getProperty("String_Node_Str","String_Node_Str") + "String_Node_Str" + "String_Node_Str"+ System.currentTimeMillis();
        traceSystem=new TraceSystem(traceFile + Constants.SUFFIX_TRACE_FILE);
      }
 else {
        traceSystem=new TraceSystem(null);
      }
    }
 else {
      traceSystem=new TraceSystem(databaseName + Constants.SUFFIX_TRACE_FILE);
    }
    traceSystem.setLevelFile(traceLevelFile);
    traceSystem.setLevelSystemOut(traceLevelSystemOut);
    trace=traceSystem.getTrace(Trace.DATABASE);
    trace.info("String_Node_Str",databaseName,Constants.BUILD_ID);
    if (autoServerMode) {
      if (readOnly || fileLockMethod == FileLock.LOCK_NO || fileLockMethod == FileLock.LOCK_SERIALIZED || fileLockMethod == FileLock.LOCK_FS || !persistent) {
        throw DbException.getUnsupportedException("String_Node_Str" + "String_Node_Str");
      }
    }
    String lockFileName=databaseName + Constants.SUFFIX_LOCK_FILE;
    if (readOnly) {
      if (FileUtils.exists(lockFileName)) {
        throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1,"String_Node_Str" + lockFileName);
      }
    }
    if (!readOnly && fileLockMethod != FileLock.LOCK_NO) {
      if (fileLockMethod != FileLock.LOCK_FS) {
        lock=new FileLock(traceSystem,lockFileName,Constants.LOCK_SLEEP);
        lock.lock(fileLockMethod);
        if (autoServerMode) {
          startServer(lock.getUniqueId());
        }
      }
    }
    if (SysProperties.MODIFY_ON_WRITE) {
      while (isReconnectNeeded()) {
      }
    }
 else {
      while (isReconnectNeeded() && !beforeWriting()) {
      }
    }
    deleteOldTempFiles();
    starting=true;
    if (SysProperties.MODIFY_ON_WRITE) {
      try {
        getPageStore();
      }
 catch (      DbException e) {
        if (e.getErrorCode() != ErrorCode.DATABASE_IS_READ_ONLY) {
          throw e;
        }
        pageStore=null;
        while (!beforeWriting()) {
        }
        getPageStore();
      }
    }
 else {
      getPageStore();
    }
    starting=false;
    if (mvStore == null) {
      writer=WriterThread.create(this,writeDelay);
    }
 else {
      setWriteDelay(writeDelay);
    }
  }
 else {
    if (autoServerMode) {
      throw DbException.getUnsupportedException("String_Node_Str");
    }
    traceSystem=new TraceSystem(null);
    trace=traceSystem.getTrace(Trace.DATABASE);
    getPageStore();
  }
  systemUser=new User(this,0,SYSTEM_USER_NAME,true);
  mainSchema=new Schema(this,0,Constants.SCHEMA_MAIN,systemUser,true);
  infoSchema=new Schema(this,-1,"String_Node_Str",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);
  lobSession=new Session(this,systemUser,++nextSessionId);
  CreateTableData data=new CreateTableData();
  ArrayList<Column> cols=data.columns;
  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));
  boolean create=true;
  if (pageStore != null) {
    create=pageStore.isNew();
  }
  data.tableName="String_Node_Str";
  data.id=0;
  data.temporary=false;
  data.persistData=persistent;
  data.persistIndexes=persistent;
  data.create=create;
  data.isHidden=true;
  data.session=systemSession;
  meta=mainSchema.createTable(data);
  IndexColumn[] pkCols=IndexColumn.wrap(new Column[]{columnId});
  metaIdIndex=meta.addIndex(systemSession,"String_Node_Str",0,pkCols,IndexType.createPrimaryKey(false,false),true,null);
  objectIds.set(0);
  starting=true;
  Cursor cursor=metaIdIndex.find(systemSession,null,null);
  ArrayList<MetaRecord> records=New.arrayList();
  while (cursor.next()) {
    MetaRecord rec=new MetaRecord(cursor.get());
    objectIds.set(rec.getId());
    records.add(rec);
  }
  Collections.sort(records);
synchronized (systemSession) {
    for (    MetaRecord rec : records) {
      rec.execute(this,systemSession,eventListener);
    }
  }
  if (mvStore != null) {
    mvStore.initTransactions();
    mvStore.removeTemporaryMaps();
  }
  recompileInvalidViews(systemSession);
  starting=false;
  if (!readOnly) {
    String name=SetTypes.getTypeName(SetTypes.CREATE_BUILD);
    if (settings.get(name) == null) {
      Setting setting=new Setting(this,allocateObjectId(),name);
      setting.setIntValue(Constants.BUILD_ID);
      lockMeta(systemSession);
      addDatabaseObject(systemSession,setting);
    }
    if (pageStore != null) {
      BitField f=pageStore.getObjectIds();
      for (int i=0, len=f.length(); i < len; i++) {
        if (f.get(i) && !objectIds.get(i)) {
          trace.info("String_Node_Str" + i);
          objectIds.set(i);
        }
      }
    }
  }
  getLobStorage().init();
  systemSession.commit(true);
  trace.info("String_Node_Str",databaseName);
  if (checkpointAllowed > 0) {
    afterWriting();
  }
}