Program: 105583
Project: 105583
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_REMOTE_ACCESS_VPN_DESTROY,eventDescription="String_Node_Str",async=true) public boolean destroyRemoteAccessVpnForIp(long ipId,Account caller) throws ResourceUnavailableException {
  final RemoteAccessVpnVO vpn=_remoteAccessVpnDao.findByPublicIpAddress(ipId);
  if (vpn == null) {
    s_logger.debug("String_Node_Str" + ipId);
    return true;
  }
  _accountMgr.checkAccess(caller,AccessType.OperateEntry,true,vpn);
  RemoteAccessVpn.State prevState=vpn.getState();
  vpn.setState(RemoteAccessVpn.State.Removed);
  _remoteAccessVpnDao.update(vpn.getId(),vpn);
  boolean success=false;
  try {
    for (    RemoteAccessVPNServiceProvider element : _vpnServiceProviders) {
      if (element.stopVpn(vpn)) {
        success=true;
        break;
      }
    }
  }
 catch (  ResourceUnavailableException ex) {
    vpn.setState(prevState);
    _remoteAccessVpnDao.update(vpn.getId(),vpn);
    s_logger.debug("String_Node_Str" + vpn.getId() + "String_Node_Str"+ RemoteAccessVpn.State.Running);
    success=false;
  }
 finally {
    if (success) {
      final List<? extends FirewallRule> vpnFwRules=_rulesDao.listByIpAndPurpose(ipId,Purpose.Vpn);
      boolean applyFirewall=false;
      final List<FirewallRuleVO> fwRules=new ArrayList<FirewallRuleVO>();
      if (vpnFwRules.size() != 0 && _rulesDao.findByRelatedId(vpnFwRules.get(0).getId()) != null) {
        applyFirewall=true;
      }
      if (applyFirewall) {
        Transaction.execute(new TransactionCallbackNoReturn(){
          @Override public void doInTransactionWithoutResult(          TransactionStatus status){
            for (            FirewallRule vpnFwRule : vpnFwRules) {
              _firewallMgr.revokeRelatedFirewallRule(vpnFwRule.getId(),false);
              fwRules.add(_rulesDao.findByRelatedId(vpnFwRule.getId()));
            }
            s_logger.debug("String_Node_Str" + fwRules.size() + "String_Node_Str");
          }
        }
);
        s_logger.debug("String_Node_Str" + ipId + "String_Node_Str");
        success=_firewallMgr.applyIngressFirewallRules(ipId,caller);
      }
      if (success) {
        try {
          Transaction.execute(new TransactionCallbackNoReturn(){
            @Override public void doInTransactionWithoutResult(            TransactionStatus status){
              _remoteAccessVpnDao.remove(vpn.getId());
              List<VpnUserVO> vpnUsers=_vpnUsersDao.listByAccount(vpn.getAccountId());
              for (              VpnUserVO user : vpnUsers) {
                if (user.getState() != VpnUser.State.Revoke) {
                  UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_REMOVE,user.getAccountId(),0,user.getId(),user.getUsername(),user.getClass().getName(),user.getUuid());
                }
              }
              if (vpnFwRules != null) {
                for (                FirewallRule vpnFwRule : vpnFwRules) {
                  _rulesDao.remove(vpnFwRule.getId());
                  s_logger.debug("String_Node_Str" + vpnFwRule.getSourceIpAddressId() + "String_Node_Str"+ vpnFwRule.getSourcePortStart()+ "String_Node_Str");
                }
              }
            }
          }
);
        }
 catch (        Exception ex) {
          s_logger.warn("String_Node_Str",ex);
        }
      }
    }
  }
  return success;
}

Fixed version (ground truth):
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_REMOTE_ACCESS_VPN_DESTROY,eventDescription="String_Node_Str",async=true) public boolean destroyRemoteAccessVpnForIp(long ipId,Account caller) throws ResourceUnavailableException {
  final RemoteAccessVpnVO vpn=_remoteAccessVpnDao.findByPublicIpAddress(ipId);
  if (vpn == null) {
    s_logger.debug("String_Node_Str" + ipId);
    return true;
  }
  _accountMgr.checkAccess(caller,AccessType.OperateEntry,true,vpn);
  RemoteAccessVpn.State prevState=vpn.getState();
  vpn.setState(RemoteAccessVpn.State.Removed);
  _remoteAccessVpnDao.update(vpn.getId(),vpn);
  boolean success=false;
  try {
    for (    RemoteAccessVPNServiceProvider element : _vpnServiceProviders) {
      if (element.stopVpn(vpn)) {
        success=true;
        break;
      }
    }
  }
 catch (  ResourceUnavailableException ex) {
    vpn.setState(prevState);
    _remoteAccessVpnDao.update(vpn.getId(),vpn);
    s_logger.debug("String_Node_Str" + vpn.getId() + "String_Node_Str"+ RemoteAccessVpn.State.Running);
    success=false;
  }
 finally {
    if (success) {
      final List<? extends FirewallRule> vpnFwRules=_rulesDao.listByIpAndPurpose(ipId,Purpose.Vpn);
      boolean applyFirewall=false;
      final List<FirewallRuleVO> fwRules=new ArrayList<FirewallRuleVO>();
      if (vpnFwRules.size() != 0 && _rulesDao.findByRelatedId(vpnFwRules.get(0).getId()) != null) {
        applyFirewall=true;
      }
      if (applyFirewall) {
        Transaction.execute(new TransactionCallbackNoReturn(){
          @Override public void doInTransactionWithoutResult(          TransactionStatus status){
            for (            FirewallRule vpnFwRule : vpnFwRules) {
              _firewallMgr.revokeRelatedFirewallRule(vpnFwRule.getId(),false);
              fwRules.add(_rulesDao.findByRelatedId(vpnFwRule.getId()));
            }
            s_logger.debug("String_Node_Str" + fwRules.size() + "String_Node_Str");
          }
        }
);
        s_logger.debug("String_Node_Str" + ipId + "String_Node_Str");
        success=_firewallMgr.applyIngressFirewallRules(ipId,caller);
      }
      if (success) {
        try {
          Transaction.execute(new TransactionCallbackNoReturn(){
            @Override public void doInTransactionWithoutResult(            TransactionStatus status){
              _remoteAccessVpnDao.remove(vpn.getId());
              List<VpnUserVO> vpnUsers=_vpnUsersDao.listByAccount(vpn.getAccountId());
              for (              VpnUserVO user : vpnUsers) {
                if (user.getState() != VpnUser.State.Revoke) {
                  UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_REMOVE,user.getAccountId(),0,user.getId(),user.getUsername(),user.getClass().getName(),user.getUuid());
                }
              }
              if (vpnFwRules != null) {
                for (                FirewallRule vpnFwRule : vpnFwRules) {
                  _rulesDao.remove(vpnFwRule.getId());
                  s_logger.debug("String_Node_Str" + vpnFwRule.getSourceIpAddressId() + "String_Node_Str"+ vpnFwRule.getSourcePortStart().intValue()+ "String_Node_Str");
                }
              }
            }
          }
);
        }
 catch (        Exception ex) {
          s_logger.warn("String_Node_Str",ex);
        }
      }
    }
  }
  return success;
}