Program: 30280
Project: 30280
Buggy source:
public void execute(AdminCommandContext context){
  final ActionReport report=context.getActionReport();
  Services services=serviceUtil.getServices();
  List<Service> matchedServices=new ArrayList<Service>();
  if (appName != null) {
    if (domain.getApplications().getApplication(appName) == null) {
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setMessage("String_Node_Str" + appName + "String_Node_Str");
      return;
    }
    for (    Service service : services.getServices()) {
      if (service instanceof ApplicationScopedService) {
        if (appName.equals(((ApplicationScopedService)service).getApplicationName())) {
          if (type != null) {
            if (service.getType().equals(type)) {
              if (scope != null) {
                if (scope.equals(getServiceScope(service))) {
                  matchedServices.add(service);
                }
              }
 else {
                matchedServices.add(service);
              }
            }
          }
 else {
            if (scope != null) {
              if (scope.equals(getServiceScope(service))) {
                matchedServices.add(service);
              }
            }
 else {
              matchedServices.add(service);
            }
          }
        }
      }
    }
    for (    ServiceRef serviceRef : services.getServiceRefs()) {
      if (appName.equals(serviceRef.getApplicationName())) {
        for (        Service service : services.getServices()) {
          if (service.getServiceName().equals(serviceRef.getServiceName())) {
            if (type != null) {
              if (service.getType().equals(type)) {
                if (scope != null) {
                  if (scope.equals(getServiceScope(service))) {
                    matchedServices.add(service);
                  }
                }
 else {
                  matchedServices.add(service);
                  break;
                }
              }
            }
 else {
              if (scope != null) {
                if (scope.equals(getServiceScope(service))) {
                  matchedServices.add(service);
                  break;
                }
 else {
                  matchedServices.add(service);
                  break;
                }
              }
            }
          }
        }
      }
    }
  }
 else {
    if (scope != null && scope.equals(SCOPE_APPLICATION)) {
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setMessage("String_Node_Str");
      return;
    }
    for (    Service service : services.getServices()) {
      if (type != null) {
        if (service.getType().equals(type)) {
          if (scope != null) {
            if (scope.equals(getServiceScope(service))) {
              matchedServices.add(service);
            }
          }
 else {
            matchedServices.add(service);
          }
        }
      }
 else {
        if (scope != null) {
          if (scope.equals(getServiceScope(service))) {
            matchedServices.add(service);
          }
        }
 else {
          matchedServices.add(service);
        }
      }
    }
  }
  Properties extraProperties=new Properties();
  extraProperties.put("String_Node_Str",new ArrayList<Map<String,String>>());
  if (matchedServices.size() > 0) {
    String headings[]=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    if (terse) {
      if (header) {
        headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
        if (type != null) {
          if (scope != null) {
            headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          }
 else {
            headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          }
        }
 else {
          if (scope != null) {
            headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          }
        }
      }
    }
 else     if (output != null) {
      String[] outputheaders=output.split("String_Node_Str");
      int count=0;
      for (      String s : outputheaders) {
        s=s.toUpperCase();
        headings[count]=s;
        count++;
      }
    }
 else {
      headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      if (type != null) {
        if (scope != null) {
          headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
        }
 else {
          headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
        }
      }
 else {
        if (scope != null) {
          headings=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
        }
      }
    }
    ColumnFormatter cf=new ColumnFormatter(headings);
    boolean foundRows=false;
    HashMap<String,String> name_map=new HashMap<String,String>();
    HashMap<String,String> ip_map=new HashMap<String,String>();
    HashMap<String,String> vm_map=new HashMap<String,String>();
    HashMap<String,String> type_map=new HashMap<String,String>();
    HashMap<String,String> state_map=new HashMap<String,String>();
    HashMap<String,String> scope_map=new HashMap<String,String>();
    for (    Service service : matchedServices) {
      foundRows=true;
      String cloudName=service.getServiceName();
      String ipAddress=service.getPropertyValue("String_Node_Str");
      if (ipAddress == null) {
        ipAddress="String_Node_Str";
      }
      String instanceID=service.getPropertyValue("String_Node_Str");
      if (instanceID == null) {
        instanceID="String_Node_Str";
      }
      String serverType=service.getType();
      String serviceType=null;
      String state="String_Node_Str";
      if (service instanceof ApplicationScopedService) {
        state=((ApplicationScopedService)service).getState();
        serviceType=SCOPE_APPLICATION;
      }
 else       if (service instanceof SharedService) {
        state=((SharedService)service).getState();
        serviceType=SCOPE_SHARED;
      }
 else       if (service instanceof ExternalService) {
        state="String_Node_Str";
        serviceType=SCOPE_EXTERNAL;
      }
      name_map.put(cloudName,cloudName);
      ip_map.put(cloudName,ipAddress);
      vm_map.put(cloudName,instanceID);
      type_map.put(cloudName,serverType);
      state_map.put(cloudName,state);
      scope_map.put(cloudName,serviceType);
      if (key == null) {
        if (output != null) {
          String outputstring[]=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          int count=0;
          for (          String s : headings) {
            if (s.equals("String_Node_Str")) {
              outputstring[count]=cloudName;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=ipAddress;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=instanceID;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=serverType;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=state;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=serviceType;
            }
            count++;
          }
          cf.addRow(outputstring);
        }
 else         if (type == null) {
          if (scope == null) {
            cf.addRow(new Object[]{cloudName,ipAddress,instanceID,serverType,state,serviceType});
          }
 else {
            if (serviceType.equals(scope)) {
              cf.addRow(new Object[]{cloudName,ipAddress,instanceID,serverType,state});
            }
          }
        }
 else {
          if (scope == null) {
            cf.addRow(new Object[]{cloudName,ipAddress,instanceID,state,serviceType});
          }
 else {
            if (serviceType.equals(scope)) {
              cf.addRow(new Object[]{cloudName,ipAddress,instanceID,state});
            }
          }
        }
      }
    }
    if (key != null) {
      if (key.equals("String_Node_Str")) {
        name_map=sortHashMap(name_map);
        for (        String e : name_map.keySet()) {
          cf.addRow(new Object[]{name_map.get(e),ip_map.get(e),vm_map.get(e),type_map.get(e),state_map.get(e),scope_map.get(e)});
        }
      }
 else       if (key.equals("String_Node_Str")) {
        ip_map=sortHashMap(ip_map);
        for (        String e : ip_map.keySet()) {
          cf.addRow(new Object[]{name_map.get(e),ip_map.get(e),vm_map.get(e),type_map.get(e),state_map.get(e),scope_map.get(e)});
        }
      }
 else       if (key.equals("String_Node_Str")) {
        vm_map=sortHashMap(vm_map);
        for (        String e : vm_map.keySet()) {
          cf.addRow(new Object[]{name_map.get(e),ip_map.get(e),vm_map.get(e),type_map.get(e),state_map.get(e),scope_map.get(e)});
        }
      }
 else       if (key.equals("String_Node_Str")) {
        type_map=sortHashMap(type_map);
        for (        String e : type_map.keySet()) {
          cf.addRow(new Object[]{name_map.get(e),ip_map.get(e),vm_map.get(e),type_map.get(e),state_map.get(e),scope_map.get(e)});
        }
      }
 else       if (key.equals("String_Node_Str")) {
        state_map=sortHashMap(state_map);
        for (        String e : state_map.keySet()) {
          cf.addRow(new Object[]{name_map.get(e),ip_map.get(e),vm_map.get(e),type_map.get(e),state_map.get(e),scope_map.get(e)});
        }
      }
 else       if (key.equals("String_Node_Str")) {
        scope_map=sortHashMap(scope_map);
        for (        String e : scope_map.keySet()) {
          cf.addRow(new Object[]{name_map.get(e),ip_map.get(e),vm_map.get(e),type_map.get(e),state_map.get(e),scope_map.get(e)});
        }
      }
    }
    if (foundRows) {
      report.setMessage(cf.toString());
      extraProperties.put("String_Node_Str",cf.getContent());
    }
 else     if (header=true) {
      report.setMessage("String_Node_Str");
    }
  }
 else   if (header=true) {
    report.setMessage("String_Node_Str");
  }
  report.setExtraProperties(extraProperties);
  ActionReport.ExitCode ec=ActionReport.ExitCode.SUCCESS;
  report.setActionExitCode(ec);
}

Fixed version (ground truth):
public void execute(AdminCommandContext context){
  final ActionReport report=context.getActionReport();
  Services services=serviceUtil.getServices();
  List<Service> matchedServices=new ArrayList<Service>();
  if (appName != null) {
    if (domain.getApplications().getApplication(appName) == null) {
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setMessage("String_Node_Str" + appName + "String_Node_Str");
      return;
    }
    for (    Service service : services.getServices()) {
      if (service instanceof ApplicationScopedService) {
        if (appName.equals(((ApplicationScopedService)service).getApplicationName())) {
          if (type != null) {
            if (service.getType().equals(type)) {
              if (scope != null) {
                if (scope.equals(getServiceScope(service))) {
                  matchedServices.add(service);
                }
              }
 else {
                matchedServices.add(service);
              }
            }
          }
 else {
            if (scope != null) {
              if (scope.equals(getServiceScope(service))) {
                matchedServices.add(service);
              }
            }
 else {
              matchedServices.add(service);
            }
          }
        }
      }
    }
    for (    ServiceRef serviceRef : services.getServiceRefs()) {
      if (appName.equals(serviceRef.getApplicationName())) {
        for (        Service service : services.getServices()) {
          if (service.getServiceName().equals(serviceRef.getServiceName())) {
            if (type != null) {
              if (service.getType().equals(type)) {
                if (scope != null) {
                  if (scope.equals(getServiceScope(service))) {
                    matchedServices.add(service);
                  }
                }
 else {
                  matchedServices.add(service);
                  break;
                }
              }
            }
 else {
              if (scope != null) {
                if (scope.equals(getServiceScope(service))) {
                  matchedServices.add(service);
                  break;
                }
 else {
                  matchedServices.add(service);
                  break;
                }
              }
            }
          }
        }
      }
    }
  }
 else {
    if (scope != null && scope.equals(SCOPE_APPLICATION)) {
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setMessage("String_Node_Str");
      return;
    }
    for (    Service service : services.getServices()) {
      if (type != null) {
        if (service.getType().equals(type)) {
          if (scope != null) {
            if (scope.equals(getServiceScope(service))) {
              matchedServices.add(service);
            }
          }
 else {
            matchedServices.add(service);
          }
        }
      }
 else {
        if (scope != null) {
          if (scope.equals(getServiceScope(service))) {
            matchedServices.add(service);
          }
        }
 else {
          matchedServices.add(service);
        }
      }
    }
  }
  Properties extraProperties=new Properties();
  extraProperties.put("String_Node_Str",new ArrayList<Map<String,String>>());
  if (matchedServices.size() > 0) {
    int heading_count=0;
    List<String> headerList=new ArrayList<String>();
    if (output != null) {
      String[] outputheaders=output.split("String_Node_Str");
      int count=0;
      for (      String s : outputheaders) {
        s=s.trim().toUpperCase();
        if (!(s.equals("String_Node_Str") || s.equals("String_Node_Str") || s.equals("String_Node_Str")|| s.equals("String_Node_Str")|| s.equals("String_Node_Str")|| s.equals("String_Node_Str"))) {
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage("String_Node_Str" + s.toLowerCase() + "String_Node_Str");
          return;
        }
        headerList.add(s);
      }
    }
 else {
      headerList.add("String_Node_Str");
      headerList.add("String_Node_Str");
      headerList.add("String_Node_Str");
      headerList.add("String_Node_Str");
      headerList.add("String_Node_Str");
      headerList.add("String_Node_Str");
      if (type != null) {
        if (scope != null) {
          headerList.remove("String_Node_Str");
          headerList.remove("String_Node_Str");
        }
 else {
          headerList.remove("String_Node_Str");
        }
      }
 else {
        if (scope != null) {
          headerList.remove("String_Node_Str");
        }
      }
    }
    ColumnFormatter cf=new ColumnFormatter();
    String[] headings=headerList.toArray(new String[headerList.size()]);
    heading_count=headerList.size();
    if (terse && (header == false)) {
      String[] s=new String[headerList.size()];
      for (int i=0; i < heading_count; i++) {
        s[i]="String_Node_Str";
      }
      cf=new ColumnFormatter(s);
    }
 else {
      cf=new ColumnFormatter(headings);
    }
    boolean foundRows=false;
    HashMap<String,String> name_map=new HashMap<String,String>();
    HashMap<String,String> ip_map=new HashMap<String,String>();
    HashMap<String,String> vm_map=new HashMap<String,String>();
    HashMap<String,String> type_map=new HashMap<String,String>();
    HashMap<String,String> state_map=new HashMap<String,String>();
    HashMap<String,String> scope_map=new HashMap<String,String>();
    for (    Service service : matchedServices) {
      foundRows=true;
      String cloudName=service.getServiceName();
      String ipAddress=service.getPropertyValue("String_Node_Str");
      if (ipAddress == null) {
        ipAddress="String_Node_Str";
      }
      String instanceID=service.getPropertyValue("String_Node_Str");
      if (instanceID == null) {
        instanceID="String_Node_Str";
      }
      String serverType=service.getType();
      String serviceType=null;
      String state="String_Node_Str";
      if (service instanceof ApplicationScopedService) {
        state=((ApplicationScopedService)service).getState();
        serviceType=SCOPE_APPLICATION;
      }
 else       if (service instanceof SharedService) {
        state=((SharedService)service).getState();
        serviceType=SCOPE_SHARED;
      }
 else       if (service instanceof ExternalService) {
        state="String_Node_Str";
        serviceType=SCOPE_EXTERNAL;
      }
      name_map.put(cloudName,cloudName);
      ip_map.put(cloudName,ipAddress);
      vm_map.put(cloudName,instanceID);
      type_map.put(cloudName,serverType);
      state_map.put(cloudName,state);
      scope_map.put(cloudName,serviceType);
      if (key == null) {
        if (output != null) {
          String[] outputstring=new String[heading_count];
          int count=0;
          for (          String s : headings) {
            if (s.equals("String_Node_Str")) {
              outputstring[count]=cloudName;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=ipAddress;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=instanceID;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=serverType;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=state;
            }
 else             if (s.equals("String_Node_Str")) {
              outputstring[count]=serviceType;
            }
            count++;
          }
          cf.addRow(outputstring);
        }
 else         if (type == null) {
          if (scope == null) {
            cf.addRow(new Object[]{cloudName,ipAddress,instanceID,serverType,state,serviceType});
          }
 else {
            if (serviceType.equals(scope)) {
              cf.addRow(new Object[]{cloudName,ipAddress,instanceID,serverType,state});
            }
          }
        }
 else {
          if (scope == null) {
            cf.addRow(new Object[]{cloudName,ipAddress,instanceID,state,serviceType});
          }
 else {
            if (serviceType.equals(scope)) {
              cf.addRow(new Object[]{cloudName,ipAddress,instanceID,state});
            }
          }
        }
      }
    }
    if (key != null) {
      if (key.equals("String_Node_Str")) {
        name_map=sortHashMap(name_map);
        for (        String e : name_map.keySet()) {
          cf.addRow(this.generateOutputRow(headings,heading_count,e,name_map,ip_map,vm_map,type_map,state_map,scope_map));
        }
      }
 else       if (key.equals("String_Node_Str")) {
        ip_map=sortHashMap(ip_map);
        for (        String e : ip_map.keySet()) {
          cf.addRow(this.generateOutputRow(headings,heading_count,e,name_map,ip_map,vm_map,type_map,state_map,scope_map));
        }
      }
 else       if (key.equals("String_Node_Str")) {
        vm_map=sortHashMap(vm_map);
        for (        String e : vm_map.keySet()) {
          cf.addRow(this.generateOutputRow(headings,heading_count,e,name_map,ip_map,vm_map,type_map,state_map,scope_map));
        }
      }
 else       if (key.equals("String_Node_Str")) {
        type_map=sortHashMap(type_map);
        for (        String e : type_map.keySet()) {
          cf.addRow(this.generateOutputRow(headings,heading_count,e,name_map,ip_map,vm_map,type_map,state_map,scope_map));
        }
      }
 else       if (key.equals("String_Node_Str")) {
        state_map=sortHashMap(state_map);
        for (        String e : state_map.keySet()) {
          cf.addRow(this.generateOutputRow(headings,heading_count,e,name_map,ip_map,vm_map,type_map,state_map,scope_map));
        }
      }
 else       if (key.equals("String_Node_Str")) {
        scope_map=sortHashMap(scope_map);
        for (        String e : scope_map.keySet()) {
          cf.addRow(this.generateOutputRow(headings,heading_count,e,name_map,ip_map,vm_map,type_map,state_map,scope_map));
        }
      }
    }
    if (foundRows) {
      report.setMessage(cf.toString());
      extraProperties.put("String_Node_Str",cf.getContent());
    }
 else     if (header=true) {
      report.setMessage("String_Node_Str");
    }
  }
 else   if (header=true) {
    report.setMessage("String_Node_Str");
  }
  report.setExtraProperties(extraProperties);
  ActionReport.ExitCode ec=ActionReport.ExitCode.SUCCESS;
  report.setActionExitCode(ec);
}