Program: 16190
Project: 16190
Buggy source:
/** 
 * Close the database.
 * @param fromShutdownHook true if this method is called from the shutdownhook
 */
synchronized void close(boolean fromShutdownHook){
  if (closing) {
    return;
  }
  if (isReconnectNeeded()) {
    try {
      closeOpenFilesAndUnlock(false);
    }
 catch (    SQLException e) {
    }
    traceSystem.close();
    Engine.getInstance().close(databaseName);
    return;
  }
  closing=true;
  stopServer();
  if (userSessions.size() > 0) {
    if (!fromShutdownHook) {
      return;
    }
    traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName + "String_Node_Str");
    Session[] all=new Session[userSessions.size()];
    userSessions.toArray(all);
    for (int i=0; i < all.length; i++) {
      Session s=all[i];
      try {
        s.rollback();
        s.close();
      }
 catch (      SQLException e) {
        traceSystem.getTrace(Trace.SESSION).error("String_Node_Str" + s.getId(),e);
      }
    }
  }
  if (log != null) {
    log.setDisabled(false);
  }
  traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName);
  if (eventListener != null) {
    closing=false;
    DatabaseEventListener e=eventListener;
    eventListener=null;
    e.closingDatabase();
    if (userSessions.size() > 0) {
      return;
    }
    closing=true;
  }
  try {
    if (systemSession != null) {
      ObjectArray tablesAndViews=getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
      for (int i=0; i < tablesAndViews.size(); i++) {
        Table table=(Table)tablesAndViews.get(i);
        table.close(systemSession);
      }
      ObjectArray sequences=getAllSchemaObjects(DbObject.SEQUENCE);
      for (int i=0; i < sequences.size(); i++) {
        Sequence sequence=(Sequence)sequences.get(i);
        sequence.close();
      }
      ObjectArray triggers=getAllSchemaObjects(DbObject.TRIGGER);
      for (int i=0; i < triggers.size(); i++) {
        TriggerObject trigger=(TriggerObject)triggers.get(i);
        trigger.close();
      }
      meta.close(systemSession);
      systemSession.commit(true);
      indexSummaryValid=true;
    }
  }
 catch (  SQLException e) {
    traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
  }
  if (persistent) {
    try {
      ValueLob.removeAllForTable(this,ValueLob.TABLE_ID_SESSION_VARIABLE);
    }
 catch (    SQLException e) {
      traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
    }
  }
  tempFileDeleter.deleteAll();
  try {
    closeOpenFilesAndUnlock(true);
  }
 catch (  SQLException e) {
    traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
  }
  traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str");
  traceSystem.close();
  if (closeOnExit != null) {
    closeOnExit.reset();
    try {
      Runtime.getRuntime().removeShutdownHook(closeOnExit);
    }
 catch (    IllegalStateException e) {
    }
catch (    SecurityException e) {
    }
    closeOnExit=null;
  }
  Engine.getInstance().close(databaseName);
  if (deleteFilesOnDisconnect && persistent) {
    deleteFilesOnDisconnect=false;
    try {
      String directory=FileUtils.getParent(databaseName);
      String name=FileUtils.getFileName(databaseName);
      DeleteDbFiles.execute(directory,name,true);
    }
 catch (    Exception e) {
    }
  }
}

Fixed version (ground truth):
/** 
 * Close the database.
 * @param fromShutdownHook true if this method is called from the shutdownhook
 */
synchronized void close(boolean fromShutdownHook){
  if (closing) {
    return;
  }
  if (fileLockMethod == FileLock.LOCK_SERIALIZED && !reconnectChangePending) {
    try {
      log.setReadOnly(true);
      closeOpenFilesAndUnlock(false);
    }
 catch (    SQLException e) {
    }
    traceSystem.close();
    Engine.getInstance().close(databaseName);
    return;
  }
  closing=true;
  stopServer();
  if (userSessions.size() > 0) {
    if (!fromShutdownHook) {
      return;
    }
    traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName + "String_Node_Str");
    Session[] all=new Session[userSessions.size()];
    userSessions.toArray(all);
    for (int i=0; i < all.length; i++) {
      Session s=all[i];
      try {
        s.rollback();
        s.close();
      }
 catch (      SQLException e) {
        traceSystem.getTrace(Trace.SESSION).error("String_Node_Str" + s.getId(),e);
      }
    }
  }
  if (log != null) {
    log.setDisabled(false);
  }
  traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str" + databaseName);
  if (eventListener != null) {
    closing=false;
    DatabaseEventListener e=eventListener;
    eventListener=null;
    e.closingDatabase();
    if (userSessions.size() > 0) {
      return;
    }
    closing=true;
  }
  try {
    if (systemSession != null) {
      ObjectArray tablesAndViews=getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
      for (int i=0; i < tablesAndViews.size(); i++) {
        Table table=(Table)tablesAndViews.get(i);
        table.close(systemSession);
      }
      ObjectArray sequences=getAllSchemaObjects(DbObject.SEQUENCE);
      for (int i=0; i < sequences.size(); i++) {
        Sequence sequence=(Sequence)sequences.get(i);
        sequence.close();
      }
      ObjectArray triggers=getAllSchemaObjects(DbObject.TRIGGER);
      for (int i=0; i < triggers.size(); i++) {
        TriggerObject trigger=(TriggerObject)triggers.get(i);
        trigger.close();
      }
      meta.close(systemSession);
      systemSession.commit(true);
      indexSummaryValid=true;
    }
  }
 catch (  SQLException e) {
    traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
  }
  if (persistent) {
    try {
      ValueLob.removeAllForTable(this,ValueLob.TABLE_ID_SESSION_VARIABLE);
    }
 catch (    SQLException e) {
      traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
    }
  }
  tempFileDeleter.deleteAll();
  try {
    closeOpenFilesAndUnlock(true);
  }
 catch (  SQLException e) {
    traceSystem.getTrace(Trace.DATABASE).error("String_Node_Str",e);
  }
  traceSystem.getTrace(Trace.DATABASE).info("String_Node_Str");
  traceSystem.close();
  if (closeOnExit != null) {
    closeOnExit.reset();
    try {
      Runtime.getRuntime().removeShutdownHook(closeOnExit);
    }
 catch (    IllegalStateException e) {
    }
catch (    SecurityException e) {
    }
    closeOnExit=null;
  }
  Engine.getInstance().close(databaseName);
  if (deleteFilesOnDisconnect && persistent) {
    deleteFilesOnDisconnect=false;
    try {
      String directory=FileUtils.getParent(databaseName);
      String name=FileUtils.getFileName(databaseName);
      DeleteDbFiles.execute(directory,name,true);
    }
 catch (    Exception e) {
    }
  }
}