Hi,

Following highlighted code segment [1] throws a NPE as it doesn't handle
the case of BillingEngine being null.

Would it be okay to log a 'warning' when it is null?

Thanks.

[1]

Class: org.wso2.carbon.throttling.manager.utils.Util.java

/**
    * get current billing customer.
    *
    * @param tenantId, tenant id.
    * @return Customer
    * @throws RegistryException, if getting the current billing customer
failed.
    */
   public static Customer getCurrentBillingCustomer(int tenantId) throws
RegistryException {
       // get the host name of the current domain
       if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
           return null;
       }
       Tenant tenant;
       try {
           tenant = (Tenant)
realmService.getTenantManager().getTenant(tenantId);
       } catch (org.wso2.carbon.user.api.UserStoreException e) {
           String msg = "Error in getting the realm Information.";
           log.error(msg, e);
           throw new RegistryException(msg, e);
       }
       if (tenant == null) {
           return null;
       }
       String customerName = tenant.getDomain();

       BillingEngine billingEngine =

 
billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
       Customer customer;

       try {
               List<Customer> customers =
billingEngine.getCustomersWithName(customerName);
               if (customers == null || customers.size() == 0) {
                   customer = null;
               } else {
                   customer = customers.get(0);
               }
      } catch (BillingException e) {
               String msg = "Error in getting the current customer";
               log.error(msg, e);
               throw new RegistryException(msg, e);
      }

      return customer;
   }



-- 

regards,
Nirmal

Software Engineer, WSO2 Inc.
mobile: +94715779733
_______________________________________________
Carbon-dev mailing list
[email protected]
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev

Reply via email to