[ 
https://issues.apache.org/jira/browse/OFBIZ-9164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16542996#comment-16542996
 ] 

Dennis Balkir commented on OFBIZ-9164:
--------------------------------------

Hi [~jacques.le.roux],

I found a mistake, which results in an Nullpointer.

If you go here: https://demo-trunk.ofbiz.apache.org/catalog/control/main then 
open the lookup on the left for category id, click the first category (20111) 
and then click on search, you will be prompted with this:
{{java.lang.IllegalArgumentException: Error running script at location 
[component://product/groovyScripts/catalog/find/KeywordSearch.groovy]: 
java.lang.NullPointerException}}

This is the result of the changes you made here, to be specific in 
{{CategoryContentWrapper}} and {{ContentWorker}}.
The following code is the problem:

{code:java}
getProductCategoryContentAsText(null, productCategory, prodCatContentTypeId, 
locale, mimeTypeId, delegator, dispatcher, outWriter, false);}}
{code}

This gives {{null}} as the value for the dispatcher, which is then used here 
inside of {{getProductCategoryContentAsText}}:
{code:java}
ContentWorker.renderContentAsText(dispatcher, 
categoryContent.getString("contentId"), outWriter, inContext, locale, 
mimeTypeId, null, null, cache);
{code}

The problem is, that the method {{renderContentAsText}} as a result of your 
changes uses the dispatcher to get the delegator:
{code:java}
public static void renderContentAsText(LocalDispatcher dispatcher, String 
contentId, Appendable out, Map<String, Object> templateContext,
            Locale locale, String mimeTypeId, String partyId, String 
roleTypeId, boolean cache) throws GeneralException, IOException {
        Delegator delegator = dispatcher.getDelegator();
        GenericValue content = ContentWorker.findContentForRendering(delegator, 
contentId, locale, partyId, roleTypeId, cache);
        ContentWorker.renderContentAsText(dispatcher, content, out, 
templateContext, locale, mimeTypeId, cache, null);
}
{code}
Because the dispatcher is a given {{null}} value at this point, this results in 
a nullpointer.

> Refactor ContentWorkerInterface methods signatures
> --------------------------------------------------
>
>                 Key: OFBIZ-9164
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-9164
>             Project: OFBiz
>          Issue Type: Sub-task
>          Components: content, framework, lucene, order, party, product, 
> workeffort
>    Affects Versions: Trunk
>            Reporter: Jacques Le Roux
>            Assignee: Jacques Le Roux
>            Priority: Minor
>             Fix For: 17.12.01
>
>         Attachments: OFBIZ-9164 DataResourceWorker.java.patch, 
> OFBIZ-9164.patch
>
>
> While working on OFBIZ-6919 which was built on R13.07 I stumbled upon an 
> issue due to r1652852 where Adrian improved the cacheKey in 
> FormFactory.getFormFromLocation() by adding a delegator reference (Tenants). 
> Actually I'm not even sure it was done at r1652852 because Adrian did not 
> maintain the FormFactory svn history.
> Anyway, to make a long story short I had to introduce a DispatchContext 
> parameter when calling FormFactory.readFormDocument() when the code from 
> R13.07 only passed a null.
> This had an impact in the hierarchy tree because 
> FormFactory.readFormDocument() was called in DataResourceWorker class, where 
> the new code was called from renderDataResourceAsText(). So I instead of only 
> passing a Delegator I decided to pass only a LocalDispatcher parameter in 
> renderDataResourceAsText(), since we can get the Delegator  from the 
> LocalDispatcher. Doing so it had an impact on the renderDataResourceAsText 
> hierarchy tree ending in DataResourceWorkerInterface and all related.
>  I finally decided to apply the same ["Change Method Signature" refactoring 
> pattern|http://refactoring.com/catalog/addParameter.html] to all cases 
> related to ContentWorkerInterface. No need to pass a delegator when you have 
> LocalDispatcher!
> Here I attach a patch for review, I'll commit in few days



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to