You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org> on 2016/02/12 04:13:18 UTC

[jira] [Commented] (MYFACES-4023) NullPointerException accessing an attribute of a component within c:forEach and partial state saving activated

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

Leonardo Uribe commented on MYFACES-4023:
-----------------------------------------

I have checked the code and the problem is the implementation of visitTree(...) does not handle VisitHint.SKIP_ITERATION hint.

Let me explain what's going on because it is a bit tricky. The method visitTree(...) is used in diferent contexts. One of those is when it is required to save and restore the view state. In those cases, a visitTree(...) call is done, but in that case, the algorithm needs to visit the "real" component instances and not the "virtual" ones, so the context should not be, and in that case the variables are part of the context.

The solution is just write these lines of code:

{code:java}
    @Override
    public boolean visitTree(final VisitContext context, final VisitCallback callback) {
        if (!isVisitable(context)) {
            return false;
        }

        if (context.getHints().contains(VisitHint.SKIP_ITERATION))
        {
            return super.visitTree(context, callback);
        }
        else
        {
            Map<String, Object> originalVars = captureOriginalVars(context.getFacesContext());
            try {
                setVars(context.getFacesContext(), getVariables());
                return super.visitTree(context, callback);
            } finally {
                setVars(context.getFacesContext(), originalVars);
            }
        }
    }
{code}

There is not a bug, so I'll close this one as invalid. Thanks for provide the example, so I could give it a try and detect the problem.

> NullPointerException accessing an attribute of a component within c:forEach and partial state saving activated
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-4023
>                 URL: https://issues.apache.org/jira/browse/MYFACES-4023
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions: 2.2.10-SNAPSHOT
>            Reporter: Johannes Grimm
>             Fix For: 2.2.10
>
>         Attachments: MyFaces-ForEach-PartialStateSaving.zip
>
>
> Accessing an attribute from with in a composite component that is contained in a forEach tag causes a null pointer exception if partial state saving is enabled.
> As the example is too complex to be shown within this report an example project can be found at https://github.com/jgrimmwsb/faces-foreach-partial-state-saving.
> Steps to reproduce the error:
> # Ensure the selected {{myfaces.version}} in the {{pom.xml}} is one of *2.2.10-SNAPSHOT*.
> # Ensure that {{javax.faces.PARTIAL_STATE_SAVING}} is set to *true* in the {{web.xml}}.
> # Start the application and open the respective website.
> # The log will show an exception like shown below:
> {code:title=Stacktrace}
> java.lang.NullPointerException
> 	at org.apache.myfaces.view.facelets.el.FaceletStateValueExpression.getWrapped(FaceletStateValueExpression.java:75)
> 	at org.apache.myfaces.view.facelets.el.FaceletStateValueExpression.getValue(FaceletStateValueExpression.java:107)
> 	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:74)
> 	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
> 	at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
> 	at javax.faces.component._ComponentAttributesMap.get(_ComponentAttributesMap.java:331)
> 	at example.Test.getVariables(Test.java:161)
> 	at example.Test.captureOriginalVars(Test.java:133)
> 	at example.Test.visitTree(Test.java:77)
> 	at javax.faces.component.UIForm.visitTree(UIForm.java:345)
> 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
> 	at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
> {code}
> With _MyFaces 2.2.7_ or _Mojarra_ the error did not occur. _MyFaces 2.2.10-SNAPSHOT_ with {{javax.faces.PARTIAL_STATE_SAVING}} is set to *false* works without error.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)