Program: 105119
Project: 105119
Buggy source:
@DB @Override public boolean applyVpnUsers(long vpnOwnerId,String userName){
  Account caller=CallContext.current().getCallingAccount();
  Account owner=_accountDao.findById(vpnOwnerId);
  _accountMgr.checkAccess(caller,null,true,owner);
  s_logger.debug("String_Node_Str" + owner);
  List<RemoteAccessVpnVO> vpns=_remoteAccessVpnDao.findByAccount(vpnOwnerId);
  List<VpnUserVO> users=_vpnUsersDao.listByAccount(vpnOwnerId);
  for (  VpnUserVO user : users) {
    if (user.getState() == State.Active) {
      user.setState(State.Add);
      _vpnUsersDao.update(user.getId(),user);
    }
  }
  boolean success=true;
  boolean[] finals=new boolean[users.size()];
  for (  RemoteAccessVPNServiceProvider element : _vpnServiceProviders) {
    s_logger.debug("String_Node_Str" + element.getName());
    for (    RemoteAccessVpnVO vpn : vpns) {
      try {
        String[] results=element.applyVpnUsers(vpn,users);
        if (results != null) {
          for (int i=0; i < results.length; i++) {
            s_logger.debug("String_Node_Str" + users.get(i) + (results[i] == null ? "String_Node_Str" : ("String_Node_Str" + results[i]) + "String_Node_Str")+ vpn);
            if (results[i] == null) {
              if (!finals[i]) {
                finals[i]=true;
              }
            }
 else {
              finals[i]=false;
              success=false;
            }
          }
        }
      }
 catch (      Exception e) {
        s_logger.warn("String_Node_Str",e);
        success=false;
        for (int i=0; i < finals.length; i++) {
          finals[i]=false;
        }
      }
    }
  }
  for (int i=0; i < finals.length; i++) {
    final VpnUserVO user=users.get(i);
    if (finals[i]) {
      if (user.getState() == State.Add) {
        user.setState(State.Active);
        _vpnUsersDao.update(user.getId(),user);
      }
 else       if (user.getState() == State.Revoke) {
        _vpnUsersDao.remove(user.getId());
      }
    }
 else {
      if (user.getState() == State.Add && (user.getUsername()).equals(userName)) {
        Transaction.execute(new TransactionCallbackNoReturn(){
          @Override public void doInTransactionWithoutResult(          TransactionStatus status){
            _vpnUsersDao.remove(user.getId());
            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_REMOVE,user.getAccountId(),0,user.getId(),user.getUsername(),user.getClass().getName(),user.getUuid());
          }
        }
);
      }
      s_logger.warn("String_Node_Str" + user.getUsername() + "String_Node_Str"+ user.getAccountId());
    }
  }
  return success;
}

Fixed version (ground truth):
@DB @Override public boolean applyVpnUsers(long vpnOwnerId,String userName) throws ResourceUnavailableException {
  Account caller=CallContext.current().getCallingAccount();
  Account owner=_accountDao.findById(vpnOwnerId);
  _accountMgr.checkAccess(caller,null,true,owner);
  s_logger.debug("String_Node_Str" + owner);
  List<RemoteAccessVpnVO> vpns=_remoteAccessVpnDao.findByAccount(vpnOwnerId);
  RemoteAccessVpnVO vpnTemp=null;
  List<VpnUserVO> users=_vpnUsersDao.listByAccount(vpnOwnerId);
  for (  VpnUserVO user : users) {
    if (user.getState() == State.Active) {
      user.setState(State.Add);
      _vpnUsersDao.update(user.getId(),user);
    }
  }
  boolean success=true;
  boolean[] finals=new boolean[users.size()];
  for (  RemoteAccessVPNServiceProvider element : _vpnServiceProviders) {
    s_logger.debug("String_Node_Str" + element.getName());
    for (    RemoteAccessVpnVO vpn : vpns) {
      try {
        String[] results=element.applyVpnUsers(vpn,users);
        if (results != null) {
          for (int i=0; i < results.length; i++) {
            s_logger.debug("String_Node_Str" + users.get(i) + (results[i] == null ? "String_Node_Str" : ("String_Node_Str" + results[i]) + "String_Node_Str")+ vpn);
            if (results[i] == null) {
              if (!finals[i]) {
                finals[i]=true;
              }
            }
 else {
              finals[i]=false;
              success=false;
              vpnTemp=vpn;
            }
          }
        }
      }
 catch (      Exception e) {
        s_logger.warn("String_Node_Str",e);
        success=false;
        vpnTemp=vpn;
        for (int i=0; i < finals.length; i++) {
          finals[i]=false;
        }
      }
    }
  }
  for (int i=0; i < finals.length; i++) {
    final VpnUserVO user=users.get(i);
    if (finals[i]) {
      if (user.getState() == State.Add) {
        user.setState(State.Active);
        _vpnUsersDao.update(user.getId(),user);
      }
 else       if (user.getState() == State.Revoke) {
        _vpnUsersDao.remove(user.getId());
      }
    }
 else {
      if (user.getState() == State.Add && (user.getUsername()).equals(userName)) {
        Transaction.execute(new TransactionCallbackNoReturn(){
          @Override public void doInTransactionWithoutResult(          TransactionStatus status){
            _vpnUsersDao.remove(user.getId());
            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_REMOVE,user.getAccountId(),0,user.getId(),user.getUsername(),user.getClass().getName(),user.getUuid());
          }
        }
);
      }
      s_logger.warn("String_Node_Str" + user.getUsername() + "String_Node_Str"+ user.getAccountId());
    }
  }
  if (!success) {
    throw new ResourceUnavailableException("String_Node_Str",RemoteAccessVPNServiceProvider.class,vpnTemp.getId());
  }
  return success;
}