Program: 9144
Project: 9144
Buggy source:
/** 
 * This constructor will initialize the different directory content upgraders and ensures that each of them are actually applicable. At the end this upgrader will have a list of   {@link Upgrader}s that needs to be executed.
 * @param baseDir The base directory of OpenAM (where the configuration can be found).
 * @param baseDN The base DN of the configuration store.
 * @throws UpgradeException If there was a problem while checking if a given Upgrader is applicable.
 */
public DirectoryContentUpgrader(String baseDir,String baseDN) throws UpgradeException {
  this.baseDir=baseDir;
  this.baseDN=baseDN;
  Key<ConnectionFactory> key=Key.get(ConnectionFactory.class,DataLayer.Types.typed(ConnectionType.DATA_LAYER));
  connFactory=InjectorHolder.getInstance(key);
  upgraders.add(new AddCTSSchema());
  upgraders.add(new CreateCTSContainer());
  if (EmbeddedOpenDS.isStarted()) {
    upgraders.add(new CreateCTSIndexes());
    upgraders.add(new AddDashboardSchema());
    upgraders.add(new AddDevicePrintSchema());
    upgraders.add(new AddUmaAuditSchema());
    upgraders.add(new AddResourceSetsSchema());
    upgraders.add(new AddUmaPendingRequestsSchema());
    upgraders.add(new AddOATHDeviceSchema());
    upgraders.add(new OATH2FASchema());
  }
  Connection conn=null;
  try {
    conn=connFactory.create();
    Schema schema=null;
    try {
      schema=Schema.readSchemaForEntry(conn,DN.valueOf(baseDN)).asStrictSchema();
    }
 catch (    ErrorResultException ere) {
      DEBUG.error("String_Node_Str",ere);
    }
    Iterator<Upgrader> it=upgraders.iterator();
    while (it.hasNext()) {
      if (!it.next().isUpgradeNecessary(conn,schema)) {
        it.remove();
      }
    }
  }
 catch (  DataLayerException ere) {
    DEBUG.error("String_Node_Str",ere);
    throw new UpgradeException(ere);
  }
 finally {
    IOUtils.closeIfNotNull(conn);
  }
}

Fixed version (ground truth):
/** 
 * This constructor will initialize the different directory content upgraders and ensures that each of them are actually applicable. At the end this upgrader will have a list of   {@link Upgrader}s that needs to be executed.
 * @param baseDir The base directory of OpenAM (where the configuration can be found).
 * @param baseDN The base DN of the configuration store.
 * @throws UpgradeException If there was a problem while checking if a given Upgrader is applicable.
 */
public DirectoryContentUpgrader(String baseDir,String baseDN) throws UpgradeException {
  this.baseDir=baseDir;
  this.baseDN=baseDN;
  isEmbedded=EmbeddedOpenDS.isStarted();
  ctsConfig=InjectorHolder.getInstance(CTSDataLayerConfiguration.class);
  Key<ConnectionFactory> key=Key.get(ConnectionFactory.class,DataLayer.Types.typed(ConnectionType.DATA_LAYER));
  connFactory=InjectorHolder.getInstance(key);
  upgraders.add(new AddCTSSchema());
  upgraders.add(new CreateCTSContainer());
  if (isEmbedded) {
    upgraders.add(new CreateCTSIndexes());
    upgraders.add(new AddDashboardSchema());
    upgraders.add(new AddDevicePrintSchema());
    upgraders.add(new AddUmaAuditSchema());
    upgraders.add(new AddResourceSetsSchema());
    upgraders.add(new AddUmaPendingRequestsSchema());
    upgraders.add(new AddOATHDeviceSchema());
    upgraders.add(new OATH2FASchema());
  }
  Connection conn=null;
  try {
    conn=connFactory.create();
    Schema schema=null;
    try {
      schema=Schema.readSchemaForEntry(conn,DN.valueOf(baseDN)).asStrictSchema();
    }
 catch (    ErrorResultException ere) {
      DEBUG.error("String_Node_Str",ere);
    }
    Iterator<Upgrader> it=upgraders.iterator();
    while (it.hasNext()) {
      if (!it.next().isUpgradeNecessary(conn,schema)) {
        it.remove();
      }
    }
  }
 catch (  DataLayerException ere) {
    DEBUG.error("String_Node_Str",ere);
    throw new UpgradeException(ere);
  }
 finally {
    IOUtils.closeIfNotNull(conn);
  }
}