Program: 16184
Project: 16184
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 (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 (    Session s : all) {
      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) {
      for (      Table table : getAllTablesAndViews()) {
        table.close(systemSession);
      }
      for (      SchemaObject obj : getAllSchemaObjects(DbObject.SEQUENCE)) {
        Sequence sequence=(Sequence)obj;
        sequence.close();
      }
      for (      SchemaObject obj : getAllSchemaObjects(DbObject.TRIGGER)) {
        TriggerObject trigger=(TriggerObject)obj;
        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 {
      if (log != null) {
        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 (    Session s : all) {
      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) {
      for (      Table table : getAllTablesAndViews()) {
        table.close(systemSession);
      }
      for (      SchemaObject obj : getAllSchemaObjects(DbObject.SEQUENCE)) {
        Sequence sequence=(Sequence)obj;
        sequence.close();
      }
      for (      SchemaObject obj : getAllSchemaObjects(DbObject.TRIGGER)) {
        TriggerObject trigger=(TriggerObject)obj;
        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) {
    }
  }
}