Program: 105592
Project: 105592
Buggy source:
protected SR getIscsiSR(Connection conn,String srNameLabel,String target,String path,String chapInitiatorUsername,String chapInitiatorPassword,boolean ignoreIntroduceException){
synchronized (srNameLabel.intern()) {
    Map<String,String> deviceConfig=new HashMap<String,String>();
    try {
      if (path.endsWith("String_Node_Str")) {
        path=path.substring(0,path.length() - 1);
      }
      String tmp[]=path.split("String_Node_Str");
      if (tmp.length != 3) {
        String msg="String_Node_Str" + path + "String_Node_Str";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
      }
      String targetiqn=tmp[1].trim();
      String lunid=tmp[2].trim();
      String scsiid="String_Node_Str";
      Set<SR> srs=SR.getByNameLabel(conn,srNameLabel);
      for (      SR sr : srs) {
        if (!SRType.LVMOISCSI.equals(sr.getType(conn))) {
          continue;
        }
        Set<PBD> pbds=sr.getPBDs(conn);
        if (pbds.isEmpty()) {
          continue;
        }
        PBD pbd=pbds.iterator().next();
        Map<String,String> dc=pbd.getDeviceConfig(conn);
        if (dc == null) {
          continue;
        }
        if (dc.get("String_Node_Str") == null) {
          continue;
        }
        if (dc.get("String_Node_Str") == null) {
          continue;
        }
        if (dc.get("String_Node_Str") == null) {
          continue;
        }
        if (target.equals(dc.get("String_Node_Str")) && targetiqn.equals(dc.get("String_Node_Str")) && lunid.equals(dc.get("String_Node_Str"))) {
          throw new CloudRuntimeException("String_Node_Str" + dc.get("String_Node_Str") + "String_Node_Str"+ dc.get("String_Node_Str")+ "String_Node_Str"+ dc.get("String_Node_Str")+ "String_Node_Str"+ srNameLabel+ "String_Node_Str"+ _host.uuid);
        }
      }
      deviceConfig.put("String_Node_Str",target);
      deviceConfig.put("String_Node_Str",targetiqn);
      if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorPassword)) {
        deviceConfig.put("String_Node_Str",chapInitiatorUsername);
        deviceConfig.put("String_Node_Str",chapInitiatorPassword);
      }
      Host host=Host.getByUuid(conn,_host.uuid);
      Map<String,String> smConfig=new HashMap<String,String>();
      String type=SRType.LVMOISCSI.toString();
      SR sr=null;
      try {
        sr=SR.create(conn,host,deviceConfig,new Long(0),srNameLabel,srNameLabel,type,"String_Node_Str",true,smConfig);
      }
 catch (      XenAPIException e) {
        String errmsg=e.toString();
        if (errmsg.contains("String_Node_Str")) {
          String lun[]=errmsg.split("String_Node_Str");
          boolean found=false;
          for (int i=1; i < lun.length; i++) {
            int blunindex=lun[i].indexOf("String_Node_Str") + 7;
            int elunindex=lun[i].indexOf("String_Node_Str");
            String ilun=lun[i].substring(blunindex,elunindex);
            ilun=ilun.trim();
            if (ilun.equals(lunid)) {
              int bscsiindex=lun[i].indexOf("String_Node_Str") + 8;
              int escsiindex=lun[i].indexOf("String_Node_Str");
              scsiid=lun[i].substring(bscsiindex,escsiindex);
              scsiid=scsiid.trim();
              found=true;
              break;
            }
          }
          if (!found) {
            String msg="String_Node_Str" + lunid + "String_Node_Str"+ errmsg;
            s_logger.warn(msg);
            throw new CloudRuntimeException(msg);
          }
        }
 else {
          String msg="String_Node_Str" + deviceConfig + "String_Node_Str"+ e.toString();
          s_logger.warn(msg,e);
          throw new CloudRuntimeException(msg,e);
        }
      }
      deviceConfig.put("String_Node_Str",scsiid);
      String result=SR.probe(conn,host,deviceConfig,type,smConfig);
      String pooluuid=null;
      if (result.indexOf("String_Node_Str") != -1) {
        pooluuid=result.substring(result.indexOf("String_Node_Str") + 6,result.indexOf("String_Node_Str")).trim();
      }
      if (pooluuid == null || pooluuid.length() != 36) {
        sr=SR.create(conn,host,deviceConfig,new Long(0),srNameLabel,srNameLabel,type,"String_Node_Str",true,smConfig);
      }
 else {
        try {
          sr=SR.introduce(conn,pooluuid,srNameLabel,srNameLabel,type,"String_Node_Str",true,smConfig);
        }
 catch (        XenAPIException ex) {
          if (ignoreIntroduceException) {
            return sr;
          }
          throw ex;
        }
        Set<Host> setHosts=Host.getAll(conn);
        for (        Host currentHost : setHosts) {
          PBD.Record rec=new PBD.Record();
          rec.deviceConfig=deviceConfig;
          rec.host=currentHost;
          rec.SR=sr;
          PBD pbd=PBD.create(conn,rec);
          pbd.plug(conn);
        }
      }
      sr.scan(conn);
      return sr;
    }
 catch (    XenAPIException e) {
      String msg="String_Node_Str" + deviceConfig + "String_Node_Str"+ e.toString();
      s_logger.warn(msg,e);
      throw new CloudRuntimeException(msg,e);
    }
catch (    Exception e) {
      String msg="String_Node_Str" + deviceConfig + "String_Node_Str"+ e.getMessage();
      s_logger.warn(msg,e);
      throw new CloudRuntimeException(msg,e);
    }
  }
}

Fixed version (ground truth):
protected SR getIscsiSR(Connection conn,String srNameLabel,String target,String path,String chapInitiatorUsername,String chapInitiatorPassword,boolean ignoreIntroduceException){
synchronized (srNameLabel.intern()) {
    Map<String,String> deviceConfig=new HashMap<String,String>();
    try {
      if (path.endsWith("String_Node_Str")) {
        path=path.substring(0,path.length() - 1);
      }
      String tmp[]=path.split("String_Node_Str");
      if (tmp.length != 3) {
        String msg="String_Node_Str" + path + "String_Node_Str";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
      }
      String targetiqn=tmp[1].trim();
      String lunid=tmp[2].trim();
      String scsiid="String_Node_Str";
      Set<SR> srs=SR.getByNameLabel(conn,srNameLabel);
      for (      SR sr : srs) {
        if (!SRType.LVMOISCSI.equals(sr.getType(conn))) {
          continue;
        }
        Set<PBD> pbds=sr.getPBDs(conn);
        if (pbds.isEmpty()) {
          continue;
        }
        PBD pbd=pbds.iterator().next();
        Map<String,String> dc=pbd.getDeviceConfig(conn);
        if (dc == null) {
          continue;
        }
        if (dc.get("String_Node_Str") == null) {
          continue;
        }
        if (dc.get("String_Node_Str") == null) {
          continue;
        }
        if (dc.get("String_Node_Str") == null) {
          continue;
        }
        if (target.equals(dc.get("String_Node_Str")) && targetiqn.equals(dc.get("String_Node_Str")) && lunid.equals(dc.get("String_Node_Str"))) {
          throw new CloudRuntimeException("String_Node_Str" + dc.get("String_Node_Str") + "String_Node_Str"+ dc.get("String_Node_Str")+ "String_Node_Str"+ dc.get("String_Node_Str")+ "String_Node_Str"+ srNameLabel+ "String_Node_Str"+ _host.uuid);
        }
      }
      deviceConfig.put("String_Node_Str",target);
      deviceConfig.put("String_Node_Str",targetiqn);
      if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorPassword)) {
        deviceConfig.put("String_Node_Str",chapInitiatorUsername);
        deviceConfig.put("String_Node_Str",chapInitiatorPassword);
      }
      Host host=Host.getByUuid(conn,_host.uuid);
      Map<String,String> smConfig=new HashMap<String,String>();
      String type=SRType.LVMOISCSI.toString();
      SR sr=null;
      try {
        sr=SR.create(conn,host,deviceConfig,new Long(0),srNameLabel,srNameLabel,type,"String_Node_Str",true,smConfig);
      }
 catch (      XenAPIException e) {
        String errmsg=e.toString();
        if (errmsg.contains("String_Node_Str")) {
          String lun[]=errmsg.split("String_Node_Str");
          boolean found=false;
          for (int i=1; i < lun.length; i++) {
            int blunindex=lun[i].indexOf("String_Node_Str") + 7;
            int elunindex=lun[i].indexOf("String_Node_Str");
            String ilun=lun[i].substring(blunindex,elunindex);
            ilun=ilun.trim();
            if (ilun.equals(lunid)) {
              int bscsiindex=lun[i].indexOf("String_Node_Str") + 8;
              int escsiindex=lun[i].indexOf("String_Node_Str");
              scsiid=lun[i].substring(bscsiindex,escsiindex);
              scsiid=scsiid.trim();
              found=true;
              break;
            }
          }
          if (!found) {
            String msg="String_Node_Str" + lunid + "String_Node_Str"+ errmsg;
            s_logger.warn(msg);
            throw new CloudRuntimeException(msg);
          }
        }
 else {
          String msg="String_Node_Str" + deviceConfig + "String_Node_Str"+ e.toString();
          s_logger.warn(msg,e);
          throw new CloudRuntimeException(msg,e);
        }
      }
      deviceConfig.put("String_Node_Str",scsiid);
      String result=SR.probe(conn,host,deviceConfig,type,smConfig);
      String pooluuid=null;
      if (result.indexOf("String_Node_Str") != -1) {
        pooluuid=result.substring(result.indexOf("String_Node_Str") + 6,result.indexOf("String_Node_Str")).trim();
      }
      if (pooluuid == null || pooluuid.length() != 36) {
        sr=SR.create(conn,host,deviceConfig,new Long(0),srNameLabel,srNameLabel,type,"String_Node_Str",true,smConfig);
      }
 else {
        try {
          sr=SR.introduce(conn,pooluuid,srNameLabel,srNameLabel,type,"String_Node_Str",true,smConfig);
        }
 catch (        XenAPIException ex) {
          if (ignoreIntroduceException) {
            return sr;
          }
          throw ex;
        }
        Set<Host> setHosts=Host.getAll(conn);
        if (setHosts == null) {
          String msg="String_Node_Str" + deviceConfig + "String_Node_Str";
          s_logger.warn(msg);
          throw new CloudRuntimeException(msg);
        }
        for (        Host currentHost : setHosts) {
          PBD.Record rec=new PBD.Record();
          rec.deviceConfig=deviceConfig;
          rec.host=currentHost;
          rec.SR=sr;
          PBD pbd=PBD.create(conn,rec);
          pbd.plug(conn);
        }
      }
      sr.scan(conn);
      return sr;
    }
 catch (    XenAPIException e) {
      String msg="String_Node_Str" + deviceConfig + "String_Node_Str"+ e.toString();
      s_logger.warn(msg,e);
      throw new CloudRuntimeException(msg,e);
    }
catch (    Exception e) {
      String msg="String_Node_Str" + deviceConfig + "String_Node_Str"+ e.getMessage();
      s_logger.warn(msg,e);
      throw new CloudRuntimeException(msg,e);
    }
  }
}