Page 1 of 1

Browse products NullPointerException

Posted: Wed Jan 09, 2013 5:36 am
by denis
Hi,

I have a strange problem on BLC (2.1.1-SNAPSHOT) with demo site.

When i click on tab "Merchandise" i have the following error :

Code: Select all

ERROR] 11:13:06 TemplateEngine - [THYMELEAF][2] Exception processing template "catalog/category": Error during execution of processor 'org.broadleafcommerce.core.web.processor.ProductOptionsProcessor' (catalog/partials/productOptions:2)
janv. 09, 2013 11:13:06 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [mycompany] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.broadleafcommerce.core.web.processor.ProductOptionsProcessor' (catalog/partials/productOptions:2)] with root cause
java.lang.NullPointerException
   at org.broadleafcommerce.core.web.processor.ProductOptionsProcessor.addAllProductOptionsToModel(ProductOptionsProcessor.java:112)
   at org.broadleafcommerce.core.web.processor.ProductOptionsProcessor.modifyModelAttributes(ProductOptionsProcessor.java:74)
   at org.broadleafcommerce.common.web.dialect.AbstractModelVariableModifierProcessor.processElement(AbstractModelVariableModifierProcessor.java:46)
   at org.thymeleaf.processor.element.AbstractElementProcessor.doProcess(AbstractElementProcessor.java:74)
   at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212)
   at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:896)
   at org.thymeleaf.dom.Node.processNode(Node.java:858)
        ...


What i have done :

1/ I created a new Product into the category "Merchandise"
2/ This Product has a custom ProductOption (MyProductOption extends ProductOptionImpl) with a custom type (MyProductOptionType extends ProductOptionType) :

Code: Select all

public class MyProductOptionType extends ProductOptionType {   
   private static final long serialVersionUID = 1L;
   public static final ProductOptionType CITY = new ProductOptionType("CITY", "city");
}


The error comes from ProductOptionsProcessor.addAllProductOptionsToModel, on the following line :

Code: Select all

dto.setType(option.getType().getType());


option.getType() return null.

So i tried to override the method getType() into MyProductOption :

Code: Select all

@Override
    public ProductOptionType getType() {
        return MyProductOptionType.getInstance(type);
    }


But it's the same problem. Which is strange is that if i put a breakpoint on this method and start demo site in Debug it works but if i remove the breakpoint the error reappears. I don't understand why, im really stuck now.

Do you have any idea ?

Thanks in advance for your help

Re: Browse products NullPointerException

Posted: Wed Jan 09, 2013 11:12 am
by phillipuniverse
The one thing I can think of is that with the debugger connected maybe it's hotswapping your code out correctly? Maybe JRebel isn't reloading that? The definitive way to check would be to do a clean/install on core and then site and see if it is still a problem.

From what I can see, however, it looks like the fix that you had in your subclass is correct.

Re: Browse products NullPointerException

Posted: Wed Jan 09, 2013 12:19 pm
by denis
Thank Philipuniverse. I did what you said (delete target repository/delete m2/clean/install) but the problem still present :shock:

I don't use JRebel. My the demo site in on a Tomcat 7.

I have added a line to check if my custom getType() is called :

Code: Select all

@Override
public ProductOptionType getType() {
       System.out.println("TYPE HERE  : "+ type);   
        return MFProductOptionType.getInstance(type);
}


Result is :

Code: Select all

TYPE HERE  : CITY
And after the stacktrace


Are you sure that the ProductOptionsProcessor is not called before custom ProductOptionType (MyProductOptionType) are set? Because is i put the breakpoint on

Code: Select all

public static ProductOptionType getInstance(final String type) {
        return TYPES.get(type);
}


TYPES doesn't contains my customs ProductOptionType (like CITY).

Re: Browse products NullPointerException

Posted: Mon Jan 14, 2013 4:41 am
by denis
The problem still present even in debug mode, have you tried to reproduce it? Thanks