Page 1 of 1

NullPointerException - CustomerState.setCustomer()

Posted: Fri Jul 04, 2014 12:46 pm
by gowthamgutha
I am getting the following error while calling CustomerState.setCustomer();

Code: Select all

java.lang.NullPointerException
   at org.broadleafcommerce.common.web.BroadleafRequestCustomerResolverImpl.setCustomer(BroadleafRequestCustomerResolverImpl.java:62)
   at org.broadleafcommerce.profile.web.core.CustomerState.setCustomer(CustomerState.java:52)


Here is the following snippet of code that caused the error.

Code: Select all

       Customer c=CustomerState.getCustomer(request);

      System.out.println("The current customer is "+c);
      
          if(c==null)
          {
             c=new CustomerImpl();
             c.setCookied(true);
             c.setAnonymous(true);
          }
       System.out.println("After init "+c);
      CustomerState.setCustomer(c);


The problem is that, BroadleafRequestContext.getBroadleafRequestContext().getWebRequest() is null. How do I solve this?

Thanks in advance. Hope you will reply as soon as possible.

Re: NullPointerException - CustomerState.setCustomer()

Posted: Tue Jul 08, 2014 2:40 am
by phillipuniverse
Ensure that BraodleafRequestFilter is executed prior to the execution of that code.