Program: 152100
Project: 152100
Buggy source:
/** 
 * Load gateways
 * @throws IOException When there is problem accessing gateway directory or files
 * @throws IntrospectionException When current JRE does not support JavaScript execution
 * @throws SAXException When related XML files are not valid
 */
public void loadGateways() throws IOException, IntrospectionException, SAXException {
  logger.fine("String_Node_Str");
  ArrayList<Gateway> globalGateways=new ArrayList<Gateway>();
  TreeSet<Gateway> localGateways=new TreeSet<Gateway>();
  HashSet<DeprecatedGateway> deprecatedGateways=new HashSet<DeprecatedGateway>();
  if (!RuntimeUtils.isRunAsWebStart() && globalGatewayDir.exists()) {
    globalGateways=new ArrayList<Gateway>(ImportManager.importGateways(globalGatewayDir));
  }
 else   if (RuntimeUtils.isRunAsWebStart()) {
    globalGateways=new ArrayList<Gateway>(ImportManager.importGateways(GATEWAY_RESOURCE));
  }
 else {
    throw new IOException("String_Node_Str" + globalGatewayDir.getAbsolutePath() + "String_Node_Str"+ GATEWAY_RESOURCE+ "String_Node_Str");
  }
  if (localGatewayDir.exists()) {
    localGateways=ImportManager.importGateways(localGatewayDir);
  }
  if (!RuntimeUtils.isRunAsWebStart() && deprecatedGWsFile.canRead()) {
    deprecatedGateways=ImportManager.importDeprecatedGateways(deprecatedGWsFile);
  }
 else   if (RuntimeUtils.isRunAsWebStart()) {
    deprecatedGateways=ImportManager.importDeprecatedGateways(DEPRECATED_GWS_RESOURCE);
  }
 else {
    logger.warning("String_Node_Str" + deprecatedGWsFile.getAbsolutePath() + "String_Node_Str"+ DEPRECATED_GWS_RESOURCE+ "String_Node_Str");
  }
  for (  DeprecatedGateway deprecated : deprecatedGateways) {
    for (Iterator<Gateway> it=globalGateways.iterator(); it.hasNext(); ) {
      Gateway op=it.next();
      if (deprecated.getName().equals(op.getName()) && deprecated.getVersion().compareTo(op.getVersion()) >= 0) {
        logger.finer("String_Node_Str" + op.getName() + "String_Node_Str");
        it.remove();
      }
    }
    for (Iterator<Gateway> it=localGateways.iterator(); it.hasNext(); ) {
      Gateway op=it.next();
      if (deprecated.getName().equals(op.getName()) && deprecated.getVersion().compareTo(op.getVersion()) >= 0) {
        logger.finer("String_Node_Str" + op.getName() + "String_Node_Str");
        it.remove();
        File opFile=null;
        try {
          opFile=new File(op.getScript().toURI());
          File opIcon=new File(opFile.getAbsolutePath().replaceFirst("String_Node_Str","String_Node_Str"));
          opFile.delete();
          FileUtils.deleteQuietly(opIcon);
        }
 catch (        Exception ex) {
          logger.log(Level.WARNING,"String_Node_Str" + op.getName() + "String_Node_Str"+ opFile+ "String_Node_Str",ex);
        }
      }
    }
  }
  for (  Gateway localOp : localGateways) {
    int index=globalGateways.indexOf(localOp);
    if (index >= 0) {
      Gateway globalOp=globalGateways.get(index);
      if (localOp.getVersion().compareTo(globalOp.getVersion()) > 0) {
        globalGateways.set(index,localOp);
        logger.finer("String_Node_Str" + localOp.getName() + "String_Node_Str");
      }
 else {
        logger.finer("String_Node_Str" + localOp.getName() + "String_Node_Str");
        File opFile=null;
        try {
          opFile=new File(localOp.getScript().toURI());
          File opIcon=new File(opFile.getAbsolutePath().replaceFirst("String_Node_Str","String_Node_Str"));
          opFile.delete();
          FileUtils.deleteQuietly(opIcon);
        }
 catch (        Exception ex) {
          logger.log(Level.WARNING,"String_Node_Str" + localOp.getName() + "String_Node_Str"+ opFile+ "String_Node_Str",ex);
        }
      }
    }
 else {
      globalGateways.add(localOp);
      logger.finer("String_Node_Str" + localOp.getName() + "String_Node_Str");
    }
  }
  Gateways.getInstance().clear();
  Gateways.getInstance().addAll(globalGateways);
  Gateways.getInstance().setDeprecatedGateways(deprecatedGateways);
}

Fixed version (ground truth):
/** 
 * Load gateways
 * @throws IOException When there is problem accessing gateway directory or files
 * @throws IntrospectionException When current JRE does not support JavaScript execution
 * @throws SAXException When related XML files are not valid
 */
public void loadGateways() throws IOException, IntrospectionException, SAXException {
  logger.fine("String_Node_Str");
  ArrayList<Gateway> globalGateways=new ArrayList<Gateway>();
  TreeSet<Gateway> localGateways=new TreeSet<Gateway>();
  HashSet<DeprecatedGateway> deprecatedGateways=new HashSet<DeprecatedGateway>();
  if (!RuntimeUtils.isRunAsWebStart() && globalGatewayDir.exists()) {
    globalGateways=new ArrayList<Gateway>(ImportManager.importGateways(globalGatewayDir,false));
  }
 else   if (RuntimeUtils.isRunAsWebStart()) {
    globalGateways=new ArrayList<Gateway>(ImportManager.importGateways(GATEWAY_RESOURCE));
  }
 else {
    throw new IOException("String_Node_Str" + globalGatewayDir.getAbsolutePath() + "String_Node_Str"+ GATEWAY_RESOURCE+ "String_Node_Str");
  }
  if (localGatewayDir.exists()) {
    localGateways=ImportManager.importGateways(localGatewayDir,true);
  }
  if (!RuntimeUtils.isRunAsWebStart() && deprecatedGWsFile.canRead()) {
    deprecatedGateways=ImportManager.importDeprecatedGateways(deprecatedGWsFile);
  }
 else   if (RuntimeUtils.isRunAsWebStart()) {
    deprecatedGateways=ImportManager.importDeprecatedGateways(DEPRECATED_GWS_RESOURCE);
  }
 else {
    logger.warning("String_Node_Str" + deprecatedGWsFile.getAbsolutePath() + "String_Node_Str"+ DEPRECATED_GWS_RESOURCE+ "String_Node_Str");
  }
  for (  DeprecatedGateway deprecated : deprecatedGateways) {
    for (Iterator<Gateway> it=globalGateways.iterator(); it.hasNext(); ) {
      Gateway op=it.next();
      if (deprecated.getName().equals(op.getName()) && deprecated.getVersion().compareTo(op.getVersion()) >= 0) {
        logger.log(Level.FINER,"String_Node_Str",op.getName());
        it.remove();
      }
    }
    for (Iterator<Gateway> it=localGateways.iterator(); it.hasNext(); ) {
      Gateway op=it.next();
      if (deprecated.getName().equals(op.getName()) && deprecated.getVersion().compareTo(op.getVersion()) >= 0) {
        logger.log(Level.FINER,"String_Node_Str",op.getName());
        it.remove();
        File opFile=null;
        try {
          opFile=new File(op.getScript().toURI());
          File opIcon=new File(opFile.getAbsolutePath().replaceFirst("String_Node_Str","String_Node_Str"));
          opFile.delete();
          FileUtils.deleteQuietly(opIcon);
        }
 catch (        Exception ex) {
          logger.log(Level.WARNING,"String_Node_Str" + op.getName() + "String_Node_Str"+ opFile+ "String_Node_Str",ex);
        }
      }
    }
  }
  for (  Gateway localOp : localGateways) {
    int index=globalGateways.indexOf(localOp);
    if (index >= 0) {
      Gateway globalOp=globalGateways.get(index);
      if (localOp.getVersion().compareTo(globalOp.getVersion()) > 0) {
        globalGateways.set(index,localOp);
        logger.log(Level.FINER,"String_Node_Str",localOp.getName());
      }
 else {
        logger.log(Level.FINER,"String_Node_Str",localOp.getName());
        File opFile=null;
        try {
          opFile=new File(localOp.getScript().toURI());
          File opIcon=new File(opFile.getAbsolutePath().replaceFirst("String_Node_Str","String_Node_Str"));
          opFile.delete();
          FileUtils.deleteQuietly(opIcon);
        }
 catch (        Exception ex) {
          logger.log(Level.WARNING,"String_Node_Str" + localOp.getName() + "String_Node_Str"+ opFile+ "String_Node_Str",ex);
        }
      }
    }
 else {
      globalGateways.add(localOp);
      logger.log(Level.FINER,"String_Node_Str",localOp.getName());
    }
  }
  Gateways.getInstance().clear();
  Gateways.getInstance().addAll(globalGateways);
  Gateways.getInstance().setDeprecatedGateways(deprecatedGateways);
}