You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Yasser Zamani (JIRA)" <ji...@apache.org> on 2018/02/19 13:38:00 UTC

[jira] [Comment Edited] (WW-4921) NPE in I18nInterceptor$SessionLocaleHandler.read

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

Yasser Zamani edited comment on WW-4921 at 2/19/18 1:37 PM:
------------------------------------------------------------

I see {{org.apache.struts2.StrutsTestCase}} inits session. Did you consider using it instead?

I see {{org.apache.struts2.StrutsTestCase#getActionProxy}} and {{org.apache.struts2.StrutsJUnit4TestCase#getActionProxy}} are exactly same except in {{StrutsTestCase}}, lines #158-161 has been refactored into a seperate function named {{initActionContext}} and also creation of session has been added. Currently I don't know if it's a design decision? or {{StrutsJUnit4TestCase}} should be changed same as {{StrutsTestCase}}?


was (Author: yasser.zamani):
I see {{org.apache.struts2.StrutsTestCase}} inits session. Did you consider using it instead?

I see {{org.apache.struts2.StrutsTestCase#getActionProxy}} and {{org.apache.struts2.StrutsJUnit4TestCase #getActionProxy}} are exactly same except {{StrutsTestCase}} has been refactored lines #158-161 into a seperate function name {{initActionContext}} and also has been added creation of session. Currently I don't know if it's a design decision? or {{StrutsJUnit4TestCase}} should be changed same as {{StrutsTestCase}}?

> NPE in I18nInterceptor$SessionLocaleHandler.read
> ------------------------------------------------
>
>                 Key: WW-4921
>                 URL: https://issues.apache.org/jira/browse/WW-4921
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>            Reporter: Michael Hintenaus
>            Priority: Major
>              Labels: test
>
> Calling
> {code:java}
> getActionProxy("/index.action").getInvocation().invoke(){code}
> in a TestCase which extends from StrutsJUnit4TestCase will lead to a NullPointerException.
> Overriding getActionProxy like this will help:
> {code:java}
>  @Override
>     protected ActionProxy getActionProxy(final String uri) {
>         final ActionProxy proxy = super.getActionProxy(uri);
>         final ActionContext context = proxy.getInvocation().getInvocationContext();
>         if (context.getSession() == null) {
>             context.setSession(new SessionMap<>(request));            
>         }
>         return proxy;
>     }{code}
>  



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