Program: 160741
Project: 160741
Buggy source:
@Action(value="String_Node_Str",results={@Result(name="String_Node_Str",location="String_Node_Str")}) public String viewSystems(){
  Long userId=AuthUtil.getUserId(servletRequest.getSession());
  String userType=AuthUtil.getUserType(servletRequest.getSession());
  List<String> ec2RegionList=EC2KeyDB.getEC2Regions();
  List<String> instanceIdList=new ArrayList<String>();
  if (sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATE) == null) {
    sortedSet.getFilterMap().put(FILTER_BY_INSTANCE_STATE,AppConfig.getProperty("String_Node_Str"));
  }
  try {
    Map<String,HostSystem> hostSystemList=new HashMap<String,HostSystem>();
    Map<String,String> tagMap=new HashMap<>();
    List<String> tagList=new ArrayList<>();
    List<Profile> profileList=UserProfileDB.getProfilesByUser(userId);
    if (profileList.size() > 0 || Auth.MANAGER.equals(userType)) {
      List<String> inputTagList=new ArrayList<String>();
      if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_TAG))) {
        inputTagList.add(sortedSet.getFilterMap().get(FILTER_BY_TAG));
      }
      for (      Profile profile : profileList) {
        inputTagList.add(profile.getTag());
      }
      for (      String tagStr : inputTagList) {
        String[] tagArr1=tagStr.split("String_Node_Str");
        if (tagArr1.length > 0) {
          for (          String tag1 : tagArr1) {
            String[] tagArr2=tag1.split("String_Node_Str");
            if (tagArr2.length > 1) {
              tagMap.put(tag1.split("String_Node_Str")[0],tag1.split("String_Node_Str")[1]);
            }
 else {
              tagList.add(tag1);
            }
          }
        }
      }
      List<String> securityGroupList=new ArrayList<>();
      if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SECURITY_GROUP))) {
        securityGroupList=Arrays.asList(sortedSet.getFilterMap().get(FILTER_BY_SECURITY_GROUP).split("String_Node_Str"));
      }
      for (      AWSCred awsCred : AWSCredDB.getAWSCredList()) {
        if (awsCred != null) {
          BasicAWSCredentials awsCredentials=new BasicAWSCredentials(awsCred.getAccessKey(),awsCred.getSecretKey());
          for (          String ec2Region : ec2RegionList) {
            AmazonEC2 service=new AmazonEC2Client(awsCredentials,AWSClientConfig.getClientConfig());
            service.setEndpoint(ec2Region);
            List<String> keyValueList=new ArrayList<String>();
            for (            EC2Key ec2Key : EC2KeyDB.getEC2KeyByRegion(ec2Region,awsCred.getId())) {
              keyValueList.add(ec2Key.getKeyNm());
            }
            DescribeInstancesRequest describeInstancesRequest=new DescribeInstancesRequest();
            Filter keyNmFilter=new Filter("String_Node_Str",keyValueList);
            describeInstancesRequest.withFilters(keyNmFilter);
            if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATE))) {
              List<String> instanceStateList=new ArrayList<String>();
              instanceStateList.add(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATE));
              Filter instanceStateFilter=new Filter("String_Node_Str",instanceStateList);
              describeInstancesRequest.withFilters(instanceStateFilter);
            }
            if (tagList.size() > 0) {
              Filter tagFilter=new Filter("String_Node_Str",tagList);
              describeInstancesRequest.withFilters(tagFilter);
            }
            if (securityGroupList.size() > 0) {
              Filter groupFilter=new Filter("String_Node_Str",securityGroupList);
              describeInstancesRequest.withFilters(groupFilter);
            }
            for (            String tag : tagMap.keySet()) {
              Filter tagValueFilter=new Filter("String_Node_Str" + tag,Arrays.asList(tagMap.get(tag)));
              describeInstancesRequest.withFilters(tagValueFilter);
            }
            DescribeInstancesResult describeInstancesResult=service.describeInstances(describeInstancesRequest);
            for (            Reservation res : describeInstancesResult.getReservations()) {
              for (              Instance instance : res.getInstances()) {
                HostSystem hostSystem=new HostSystem();
                hostSystem.setInstance(instance.getInstanceId());
                if (!"String_Node_Str".equals(AppConfig.getProperty("String_Node_Str")) && StringUtils.isNotEmpty(instance.getPublicDnsName())) {
                  hostSystem.setHost(instance.getPublicDnsName());
                }
 else                 if (!"String_Node_Str".equals(AppConfig.getProperty("String_Node_Str")) && StringUtils.isNotEmpty(instance.getPublicIpAddress())) {
                  hostSystem.setHost(instance.getPublicIpAddress());
                }
 else                 if (StringUtils.isNotEmpty(instance.getPrivateDnsName())) {
                  hostSystem.setHost(instance.getPrivateDnsName());
                }
 else {
                  hostSystem.setHost(instance.getPrivateIpAddress());
                }
                hostSystem.setKeyId(EC2KeyDB.getEC2KeyByNmRegion(instance.getKeyName(),ec2Region,awsCred.getId()).getId());
                hostSystem.setEc2Region(ec2Region);
                hostSystem.setState(instance.getState().getName());
                for (                Tag tag : instance.getTags()) {
                  if ("String_Node_Str".equals(tag.getKey())) {
                    hostSystem.setDisplayNm(tag.getValue());
                  }
                }
                instanceIdList.add(hostSystem.getInstance());
                hostSystemList.put(hostSystem.getInstance(),hostSystem);
              }
            }
            if (instanceIdList.size() > 0) {
              servletRequest.getSession().setAttribute("String_Node_Str",new ArrayList<String>(instanceIdList));
              if (showStatus) {
                int i=0;
                List<String> idCallList=new ArrayList<String>();
                while (!instanceIdList.isEmpty()) {
                  idCallList.add(instanceIdList.remove(0));
                  i++;
                  if (i >= 100 || instanceIdList.isEmpty()) {
                    DescribeInstanceStatusRequest describeInstanceStatusRequest=new DescribeInstanceStatusRequest();
                    describeInstanceStatusRequest.withInstanceIds(idCallList);
                    DescribeInstanceStatusResult describeInstanceStatusResult=service.describeInstanceStatus(describeInstanceStatusRequest);
                    for (                    InstanceStatus instanceStatus : describeInstanceStatusResult.getInstanceStatuses()) {
                      HostSystem hostSystem=hostSystemList.remove(instanceStatus.getInstanceId());
                      hostSystem.setSystemStatus(instanceStatus.getSystemStatus().getStatus());
                      hostSystem.setInstanceStatus(instanceStatus.getInstanceStatus().getStatus());
                      if ((StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)) && StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS))) || (hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)) && StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS))) || (hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS)) && StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)))|| (hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS)) && hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)))) {
                        hostSystemList.put(hostSystem.getInstance(),hostSystem);
                      }
                    }
                    i=0;
                    idCallList.clear();
                  }
                }
                AmazonCloudWatchClient cloudWatchClient=new AmazonCloudWatchClient(awsCredentials,AWSClientConfig.getClientConfig());
                cloudWatchClient.setEndpoint(ec2Region.replace("String_Node_Str","String_Node_Str"));
                DescribeAlarmsResult describeAlarmsResult=cloudWatchClient.describeAlarms();
                for (                MetricAlarm metricAlarm : describeAlarmsResult.getMetricAlarms()) {
                  for (                  Dimension dim : metricAlarm.getDimensions()) {
                    if (dim.getName().equals("String_Node_Str")) {
                      HostSystem hostSystem=hostSystemList.remove(dim.getValue());
                      if (hostSystem != null) {
                        if ("String_Node_Str".equals(metricAlarm.getStateValue())) {
                          hostSystem.setMonitorAlarm(hostSystem.getMonitorAlarm() + 1);
                        }
 else                         if ("String_Node_Str".equals(metricAlarm.getStateValue())) {
                          hostSystem.setMonitorInsufficientData(hostSystem.getMonitorInsufficientData() + 1);
                        }
 else {
                          hostSystem.setMonitorOk(hostSystem.getMonitorOk() + 1);
                        }
                        if (StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE))) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
 else                         if ("String_Node_Str".equals(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE)) && hostSystem.getMonitorAlarm() > 0) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
 else                         if ("String_Node_Str".equals(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE)) && hostSystem.getMonitorInsufficientData() > 0) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
 else                         if ("String_Node_Str".equals(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE)) && hostSystem.getMonitorOk() > 0 && hostSystem.getMonitorInsufficientData() <= 0 && hostSystem.getMonitorAlarm() <= 0) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      SystemDB.setSystems(hostSystemList.values());
      sortedSet=SystemDB.getSystemSet(sortedSet,new ArrayList<String>(hostSystemList.keySet()));
    }
  }
 catch (  AmazonServiceException ex) {
    ex.printStackTrace();
  }
  if (script != null && script.getId() != null) {
    script=ScriptDB.getScript(script.getId(),userId);
  }
  return SUCCESS;
}

Fixed version (ground truth):
@Action(value="String_Node_Str",results={@Result(name="String_Node_Str",location="String_Node_Str")}) public String viewSystems(){
  Long userId=AuthUtil.getUserId(servletRequest.getSession());
  String userType=AuthUtil.getUserType(servletRequest.getSession());
  List<String> ec2RegionList=EC2KeyDB.getEC2Regions();
  List<String> instanceIdList=new ArrayList<String>();
  if (sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATE) == null) {
    sortedSet.getFilterMap().put(FILTER_BY_INSTANCE_STATE,AppConfig.getProperty("String_Node_Str"));
  }
  try {
    Map<String,HostSystem> hostSystemList=new HashMap<String,HostSystem>();
    Map<String,List<String>> tagMap=new HashMap<>();
    List<String> tagList=new ArrayList<>();
    List<Profile> profileList=UserProfileDB.getProfilesByUser(userId);
    if (profileList.size() > 0 || Auth.MANAGER.equals(userType)) {
      List<String> inputTagList=new ArrayList<String>();
      if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_TAG))) {
        inputTagList.add(sortedSet.getFilterMap().get(FILTER_BY_TAG));
      }
      for (      Profile profile : profileList) {
        inputTagList.add(profile.getTag());
      }
      for (      String tagStr : inputTagList) {
        String[] tagArr1=tagStr.split("String_Node_Str");
        if (tagArr1.length > 0) {
          for (          String tag1 : tagArr1) {
            String[] tagArr2=tag1.split("String_Node_Str");
            if (tagArr2.length > 1) {
              String tagNm=tag1.split("String_Node_Str")[0];
              String tagVal=tag1.split("String_Node_Str")[1];
              if (tagMap.get(tagNm) != null && tagMap.get(tagNm).size() > 0) {
                tagMap.get(tagNm).add(tagVal);
              }
 else {
                tagMap.put(tagNm,new LinkedList<String>());
                tagMap.get(tagNm).add(tagVal);
              }
            }
 else {
              tagList.add(tag1);
            }
          }
        }
      }
      List<String> securityGroupList=new ArrayList<>();
      if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SECURITY_GROUP))) {
        securityGroupList=Arrays.asList(sortedSet.getFilterMap().get(FILTER_BY_SECURITY_GROUP).split("String_Node_Str"));
      }
      for (      AWSCred awsCred : AWSCredDB.getAWSCredList()) {
        if (awsCred != null) {
          BasicAWSCredentials awsCredentials=new BasicAWSCredentials(awsCred.getAccessKey(),awsCred.getSecretKey());
          for (          String ec2Region : ec2RegionList) {
            AmazonEC2 service=new AmazonEC2Client(awsCredentials,AWSClientConfig.getClientConfig());
            service.setEndpoint(ec2Region);
            List<String> keyValueList=new ArrayList<String>();
            for (            EC2Key ec2Key : EC2KeyDB.getEC2KeyByRegion(ec2Region,awsCred.getId())) {
              keyValueList.add(ec2Key.getKeyNm());
            }
            DescribeInstancesRequest describeInstancesRequest=new DescribeInstancesRequest();
            Filter keyNmFilter=new Filter("String_Node_Str",keyValueList);
            describeInstancesRequest.withFilters(keyNmFilter);
            if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATE))) {
              List<String> instanceStateList=new ArrayList<String>();
              instanceStateList.add(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATE));
              Filter instanceStateFilter=new Filter("String_Node_Str",instanceStateList);
              describeInstancesRequest.withFilters(instanceStateFilter);
            }
            if (tagList.size() > 0) {
              Filter tagFilter=new Filter("String_Node_Str",tagList);
              describeInstancesRequest.withFilters(tagFilter);
            }
            if (securityGroupList.size() > 0) {
              Filter groupFilter=new Filter("String_Node_Str",securityGroupList);
              describeInstancesRequest.withFilters(groupFilter);
            }
            for (            String tag : tagMap.keySet()) {
              Filter tagValueFilter=new Filter("String_Node_Str" + tag,tagMap.get(tag));
              describeInstancesRequest.withFilters(tagValueFilter);
            }
            DescribeInstancesResult describeInstancesResult=service.describeInstances(describeInstancesRequest);
            for (            Reservation res : describeInstancesResult.getReservations()) {
              for (              Instance instance : res.getInstances()) {
                HostSystem hostSystem=new HostSystem();
                hostSystem.setInstance(instance.getInstanceId());
                if (!"String_Node_Str".equals(AppConfig.getProperty("String_Node_Str")) && StringUtils.isNotEmpty(instance.getPublicDnsName())) {
                  hostSystem.setHost(instance.getPublicDnsName());
                }
 else                 if (!"String_Node_Str".equals(AppConfig.getProperty("String_Node_Str")) && StringUtils.isNotEmpty(instance.getPublicIpAddress())) {
                  hostSystem.setHost(instance.getPublicIpAddress());
                }
 else                 if (StringUtils.isNotEmpty(instance.getPrivateDnsName())) {
                  hostSystem.setHost(instance.getPrivateDnsName());
                }
 else {
                  hostSystem.setHost(instance.getPrivateIpAddress());
                }
                hostSystem.setKeyId(EC2KeyDB.getEC2KeyByNmRegion(instance.getKeyName(),ec2Region,awsCred.getId()).getId());
                hostSystem.setEc2Region(ec2Region);
                hostSystem.setState(instance.getState().getName());
                for (                Tag tag : instance.getTags()) {
                  if ("String_Node_Str".equals(tag.getKey())) {
                    hostSystem.setDisplayNm(tag.getValue());
                  }
                }
                instanceIdList.add(hostSystem.getInstance());
                hostSystemList.put(hostSystem.getInstance(),hostSystem);
              }
            }
            if (instanceIdList.size() > 0) {
              servletRequest.getSession().setAttribute("String_Node_Str",new ArrayList<String>(instanceIdList));
              if (showStatus) {
                int i=0;
                List<String> idCallList=new ArrayList<String>();
                while (!instanceIdList.isEmpty()) {
                  idCallList.add(instanceIdList.remove(0));
                  i++;
                  if (i >= 100 || instanceIdList.isEmpty()) {
                    DescribeInstanceStatusRequest describeInstanceStatusRequest=new DescribeInstanceStatusRequest();
                    describeInstanceStatusRequest.withInstanceIds(idCallList);
                    DescribeInstanceStatusResult describeInstanceStatusResult=service.describeInstanceStatus(describeInstanceStatusRequest);
                    for (                    InstanceStatus instanceStatus : describeInstanceStatusResult.getInstanceStatuses()) {
                      HostSystem hostSystem=hostSystemList.remove(instanceStatus.getInstanceId());
                      hostSystem.setSystemStatus(instanceStatus.getSystemStatus().getStatus());
                      hostSystem.setInstanceStatus(instanceStatus.getInstanceStatus().getStatus());
                      if ((StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)) && StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS))) || (hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)) && StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS))) || (hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS)) && StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)))|| (hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_STATUS)) && hostSystem.getInstanceStatus().equals(sortedSet.getFilterMap().get(FILTER_BY_INSTANCE_STATUS)))) {
                        hostSystemList.put(hostSystem.getInstance(),hostSystem);
                      }
                    }
                    i=0;
                    idCallList.clear();
                  }
                }
                AmazonCloudWatchClient cloudWatchClient=new AmazonCloudWatchClient(awsCredentials,AWSClientConfig.getClientConfig());
                cloudWatchClient.setEndpoint(ec2Region.replace("String_Node_Str","String_Node_Str"));
                DescribeAlarmsResult describeAlarmsResult=cloudWatchClient.describeAlarms();
                for (                MetricAlarm metricAlarm : describeAlarmsResult.getMetricAlarms()) {
                  for (                  Dimension dim : metricAlarm.getDimensions()) {
                    if (dim.getName().equals("String_Node_Str")) {
                      HostSystem hostSystem=hostSystemList.remove(dim.getValue());
                      if (hostSystem != null) {
                        if ("String_Node_Str".equals(metricAlarm.getStateValue())) {
                          hostSystem.setMonitorAlarm(hostSystem.getMonitorAlarm() + 1);
                        }
 else                         if ("String_Node_Str".equals(metricAlarm.getStateValue())) {
                          hostSystem.setMonitorInsufficientData(hostSystem.getMonitorInsufficientData() + 1);
                        }
 else {
                          hostSystem.setMonitorOk(hostSystem.getMonitorOk() + 1);
                        }
                        if (StringUtils.isEmpty(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE))) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
 else                         if ("String_Node_Str".equals(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE)) && hostSystem.getMonitorAlarm() > 0) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
 else                         if ("String_Node_Str".equals(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE)) && hostSystem.getMonitorInsufficientData() > 0) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
 else                         if ("String_Node_Str".equals(sortedSet.getFilterMap().get(FILTER_BY_ALARM_STATE)) && hostSystem.getMonitorOk() > 0 && hostSystem.getMonitorInsufficientData() <= 0 && hostSystem.getMonitorAlarm() <= 0) {
                          hostSystemList.put(hostSystem.getInstance(),hostSystem);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      SystemDB.setSystems(hostSystemList.values());
      sortedSet=SystemDB.getSystemSet(sortedSet,new ArrayList<String>(hostSystemList.keySet()));
    }
  }
 catch (  AmazonServiceException ex) {
    ex.printStackTrace();
  }
  if (script != null && script.getId() != null) {
    script=ScriptDB.getScript(script.getId(),userId);
  }
  return SUCCESS;
}