Program: 106845
Project: 106845
Buggy source:
@Override public UserVmResponse listVmDetails(UserVm userVm,boolean show_host){
  Transaction txn=Transaction.currentTxn();
  PreparedStatement pstmt=null;
  try {
    String sql=VM_DETAILS;
    pstmt=txn.prepareAutoCloseStatement(sql);
    pstmt.setLong(1,userVm.getId());
    ResultSet rs=pstmt.executeQuery();
    boolean is_data_center_security_group_enabled=false;
    Set<SecurityGroupResponse> securityGroupResponse=new HashSet<SecurityGroupResponse>();
    Set<NicResponse> nicResponses=new HashSet<NicResponse>();
    UserVmResponse userVmResponse=null;
    while (rs.next()) {
      if (userVmResponse == null) {
        userVmResponse=new UserVmResponse();
        userVmResponse.setId(userVm.getId());
        userVmResponse.setName(userVm.getDisplayName());
        userVmResponse.setCreated(userVm.getCreated());
        userVmResponse.setGuestOsId(userVm.getGuestOSId());
        userVmResponse.setHaEnable(userVm.isHaEnabled());
        if (userVm.getState() != null) {
          userVmResponse.setState(userVm.getState().toString());
        }
        if (userVm.getDisplayName() != null) {
          userVmResponse.setDisplayName(userVm.getDisplayName());
        }
 else {
          userVmResponse.setDisplayName(userVm.getHostName());
        }
        userVmResponse.setAccountName(rs.getString("String_Node_Str"));
        userVmResponse.setDomainId(userVm.getDomainId());
        userVmResponse.setDomainName(rs.getString("String_Node_Str"));
        long grp_id=rs.getLong("String_Node_Str");
        if (grp_id > 0) {
          userVmResponse.setGroupId(grp_id);
          userVmResponse.setGroup(rs.getString("String_Node_Str"));
        }
        userVmResponse.setZoneId(rs.getLong("String_Node_Str"));
        userVmResponse.setZoneName(rs.getString("String_Node_Str"));
        if (show_host) {
          userVmResponse.setHostId(rs.getLong("String_Node_Str"));
          userVmResponse.setHostName(rs.getString("String_Node_Str"));
        }
        if (userVm.getHypervisorType() != null) {
          userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
        }
        long template_id=rs.getLong("String_Node_Str");
        if (template_id > 0) {
          userVmResponse.setTemplateId(template_id);
          userVmResponse.setTemplateName(rs.getString("String_Node_Str"));
          userVmResponse.setTemplateDisplayText(rs.getString("String_Node_Str"));
          userVmResponse.setPasswordEnabled(rs.getBoolean("String_Node_Str"));
        }
 else {
          userVmResponse.setTemplateId(-1L);
          userVmResponse.setTemplateName("String_Node_Str");
          userVmResponse.setTemplateDisplayText("String_Node_Str");
          userVmResponse.setPasswordEnabled(false);
        }
        if (userVm.getPassword() != null) {
          userVmResponse.setPassword(userVm.getPassword());
        }
        userVmResponse.setServiceOfferingId(rs.getLong("String_Node_Str"));
        userVmResponse.setServiceOfferingName(rs.getString("String_Node_Str"));
        userVmResponse.setCpuNumber(rs.getInt("String_Node_Str"));
        userVmResponse.setCpuSpeed(rs.getInt("String_Node_Str"));
        userVmResponse.setMemory(rs.getInt("String_Node_Str"));
        long vol_id=rs.getLong("String_Node_Str");
        if (vol_id > 0) {
          userVmResponse.setRootDeviceId(rs.getLong("String_Node_Str"));
          userVmResponse.setRootDeviceType(rs.getString("String_Node_Str"));
          long pool_id=rs.getLong("String_Node_Str");
          if (pool_id > 0) {
            userVmResponse.setRootDeviceType(rs.getString("String_Node_Str"));
          }
 else {
            userVmResponse.setRootDeviceType("String_Node_Str");
          }
        }
        is_data_center_security_group_enabled=rs.getBoolean("String_Node_Str");
      }
      if (is_data_center_security_group_enabled) {
        SecurityGroupResponse resp=new SecurityGroupResponse();
        resp.setId(rs.getLong("String_Node_Str"));
        resp.setName("String_Node_Str");
        resp.setDescription("String_Node_Str");
        resp.setObjectName("String_Node_Str");
        securityGroupResponse.add(resp);
      }
      long nic_id=rs.getLong("String_Node_Str");
      if (nic_id > 0) {
        NicResponse nicResponse=new NicResponse();
        nicResponse.setId(nic_id);
        nicResponse.setIpaddress(rs.getString("String_Node_Str"));
        nicResponse.setGateway(rs.getString("String_Node_Str"));
        nicResponse.setNetmask(rs.getString("String_Node_Str"));
        nicResponse.setNetworkid(rs.getLong("String_Node_Str"));
        nicResponse.setMacAddress(rs.getString("String_Node_Str"));
        int account_type=rs.getInt("String_Node_Str");
        if (account_type == Account.ACCOUNT_TYPE_ADMIN) {
          nicResponse.setBroadcastUri(rs.getString("String_Node_Str"));
          nicResponse.setIsolationUri(rs.getString("String_Node_Str"));
        }
        nicResponse.setTrafficType(rs.getString("String_Node_Str"));
        nicResponse.setType(rs.getString("String_Node_Str"));
        nicResponse.setIsDefault(rs.getBoolean("String_Node_Str"));
        nicResponse.setObjectName("String_Node_Str");
        nicResponses.add(nicResponse);
      }
    }
    userVmResponse.setSecurityGroupList(new ArrayList(securityGroupResponse));
    userVmResponse.setNics(new ArrayList(nicResponses));
    return userVmResponse;
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str" + VM_DETAILS,e);
  }
catch (  Throwable e) {
    throw new CloudRuntimeException("String_Node_Str" + VM_DETAILS,e);
  }
}

Fixed version (ground truth):
@Override public UserVmResponse listVmDetails(UserVm userVm,boolean show_host){
  Transaction txn=Transaction.currentTxn();
  PreparedStatement pstmt=null;
  try {
    String sql=VM_DETAILS;
    pstmt=txn.prepareAutoCloseStatement(sql);
    pstmt.setLong(1,userVm.getIsoId() == null ? -1 : userVm.getIsoId());
    pstmt.setLong(2,userVm.getId());
    ResultSet rs=pstmt.executeQuery();
    boolean is_data_center_security_group_enabled=false;
    Set<SecurityGroupResponse> securityGroupResponse=new HashSet<SecurityGroupResponse>();
    Set<NicResponse> nicResponses=new HashSet<NicResponse>();
    UserVmResponse userVmResponse=null;
    while (rs.next()) {
      if (userVmResponse == null) {
        userVmResponse=new UserVmResponse();
        userVmResponse.setId(userVm.getId());
        userVmResponse.setName(userVm.getDisplayName());
        userVmResponse.setCreated(userVm.getCreated());
        userVmResponse.setGuestOsId(userVm.getGuestOSId());
        userVmResponse.setHaEnable(userVm.isHaEnabled());
        if (userVm.getState() != null) {
          userVmResponse.setState(userVm.getState().toString());
        }
        if (userVm.getDisplayName() != null) {
          userVmResponse.setDisplayName(userVm.getDisplayName());
        }
 else {
          userVmResponse.setDisplayName(userVm.getHostName());
        }
        userVmResponse.setAccountName(rs.getString("String_Node_Str"));
        userVmResponse.setDomainId(userVm.getDomainId());
        userVmResponse.setDomainName(rs.getString("String_Node_Str"));
        long grp_id=rs.getLong("String_Node_Str");
        if (grp_id > 0) {
          userVmResponse.setGroupId(grp_id);
          userVmResponse.setGroup(rs.getString("String_Node_Str"));
        }
        userVmResponse.setZoneId(rs.getLong("String_Node_Str"));
        userVmResponse.setZoneName(rs.getString("String_Node_Str"));
        if (show_host) {
          userVmResponse.setHostId(rs.getLong("String_Node_Str"));
          userVmResponse.setHostName(rs.getString("String_Node_Str"));
        }
        if (userVm.getHypervisorType() != null) {
          userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
        }
        long template_id=rs.getLong("String_Node_Str");
        if (template_id > 0) {
          userVmResponse.setTemplateId(template_id);
          userVmResponse.setTemplateName(rs.getString("String_Node_Str"));
          userVmResponse.setTemplateDisplayText(rs.getString("String_Node_Str"));
          userVmResponse.setPasswordEnabled(rs.getBoolean("String_Node_Str"));
        }
 else {
          userVmResponse.setTemplateId(-1L);
          userVmResponse.setTemplateName("String_Node_Str");
          userVmResponse.setTemplateDisplayText("String_Node_Str");
          userVmResponse.setPasswordEnabled(false);
        }
        long iso_id=rs.getLong("String_Node_Str");
        if (iso_id > 0) {
          userVmResponse.setIsoId(iso_id);
          userVmResponse.setIsoName(rs.getString("String_Node_Str"));
        }
        if (userVm.getPassword() != null) {
          userVmResponse.setPassword(userVm.getPassword());
        }
        userVmResponse.setServiceOfferingId(rs.getLong("String_Node_Str"));
        userVmResponse.setServiceOfferingName(rs.getString("String_Node_Str"));
        userVmResponse.setCpuNumber(rs.getInt("String_Node_Str"));
        userVmResponse.setCpuSpeed(rs.getInt("String_Node_Str"));
        userVmResponse.setMemory(rs.getInt("String_Node_Str"));
        long vol_id=rs.getLong("String_Node_Str");
        if (vol_id > 0) {
          userVmResponse.setRootDeviceId(rs.getLong("String_Node_Str"));
          userVmResponse.setRootDeviceType(rs.getString("String_Node_Str"));
          long pool_id=rs.getLong("String_Node_Str");
          if (pool_id > 0) {
            userVmResponse.setRootDeviceType(rs.getString("String_Node_Str"));
          }
 else {
            userVmResponse.setRootDeviceType("String_Node_Str");
          }
        }
        is_data_center_security_group_enabled=rs.getBoolean("String_Node_Str");
      }
      if (is_data_center_security_group_enabled) {
        SecurityGroupResponse resp=new SecurityGroupResponse();
        resp.setId(rs.getLong("String_Node_Str"));
        resp.setName("String_Node_Str");
        resp.setDescription("String_Node_Str");
        resp.setObjectName("String_Node_Str");
        securityGroupResponse.add(resp);
      }
      long nic_id=rs.getLong("String_Node_Str");
      if (nic_id > 0) {
        NicResponse nicResponse=new NicResponse();
        nicResponse.setId(nic_id);
        nicResponse.setIpaddress(rs.getString("String_Node_Str"));
        nicResponse.setGateway(rs.getString("String_Node_Str"));
        nicResponse.setNetmask(rs.getString("String_Node_Str"));
        nicResponse.setNetworkid(rs.getLong("String_Node_Str"));
        nicResponse.setMacAddress(rs.getString("String_Node_Str"));
        int account_type=rs.getInt("String_Node_Str");
        if (account_type == Account.ACCOUNT_TYPE_ADMIN) {
          nicResponse.setBroadcastUri(rs.getString("String_Node_Str"));
          nicResponse.setIsolationUri(rs.getString("String_Node_Str"));
        }
        nicResponse.setTrafficType(rs.getString("String_Node_Str"));
        nicResponse.setType(rs.getString("String_Node_Str"));
        nicResponse.setIsDefault(rs.getBoolean("String_Node_Str"));
        nicResponse.setObjectName("String_Node_Str");
        nicResponses.add(nicResponse);
      }
    }
    userVmResponse.setSecurityGroupList(new ArrayList(securityGroupResponse));
    userVmResponse.setNics(new ArrayList(nicResponses));
    return userVmResponse;
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str" + VM_DETAILS,e);
  }
catch (  Throwable e) {
    throw new CloudRuntimeException("String_Node_Str" + VM_DETAILS,e);
  }
}