You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Gustavo De Sanctis (JIRA)" <ji...@apache.org> on 2009/06/18 10:51:42 UTC

[jira] Created: (WW-3161) When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)

When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)
-------------------------------------------------------------------------------------------------

                 Key: WW-3161
                 URL: https://issues.apache.org/struts/browse/WW-3161
             Project: Struts 2
          Issue Type: Bug
          Components: Core Interceptors
    Affects Versions: 2.1.6
            Reporter: Gustavo De Sanctis


I have a simple action that extends ActionSupport and uses the execAndWait interceptor.
In the "execute" method there is a getText("samekey") that fails with:

java.lang.NullPointerException

    com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:318)
    com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:191)
    com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:106)
    com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:80)
    it.test.SimpleAction.execute(SimpleAction.java:10)


When using the default interceptor stack, it works fine.

My guess is that as the action context is threadlocal and as the execAndWait interceptor creates a new thread to handle the request... this new thread has no reference to the action context (infact ActionContext.getContext() returns null when using execAndWait)



Below the data to reproduce the problem:

*****************************
ACTION CLASS: it.test.SimpleAction
*****************************
package it.test;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class SimpleAction extends ActionSupport {

	public String execute(){
		System.out.println(ActionContext.getContext());
		addActionMessage(getText("message.sample","ciao"));
		return SUCCESS;
	}
}

***********************
 Struts config 
************************
<action name="simple" class="it.test.SimpleAction">
   <interceptor-ref name="execAndWait" />
   <result name="success">/simple.jsp</result>
</action>

***********************
simple.jsp
**********************
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple </title>
</head>
<body>
<s:actionmessage/>
</body>
</html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-3161) When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)

Posted by "Wes Wannemacher (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-3161?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wes Wannemacher updated WW-3161:
--------------------------------

    Fix Version/s: 2.1.8

bumping to 2.1.8

> When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)
> -------------------------------------------------------------------------------------------------
>
>                 Key: WW-3161
>                 URL: https://issues.apache.org/struts/browse/WW-3161
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.1.6
>            Reporter: Gustavo De Sanctis
>             Fix For: 2.1.8
>
>
> I have a simple action that extends ActionSupport and uses the execAndWait interceptor.
> In the "execute" method there is a getText("samekey") that fails with:
> java.lang.NullPointerException
>     com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:318)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:191)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:106)
>     com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:80)
>     it.test.SimpleAction.execute(SimpleAction.java:10)
> When using the default interceptor stack, it works fine.
> My guess is that as the action context is threadlocal and as the execAndWait interceptor creates a new thread to handle the request... this new thread has no reference to the action context (infact ActionContext.getContext() returns null when using execAndWait)
> Below the data to reproduce the problem:
> *****************************
> ACTION CLASS: it.test.SimpleAction
> *****************************
> package it.test;
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.ActionSupport;
> public class SimpleAction extends ActionSupport {
> 	public String execute(){
> 		System.out.println(ActionContext.getContext());
> 		addActionMessage(getText("message.sample","ciao"));
> 		return SUCCESS;
> 	}
> }
> ***********************
>  Struts config 
> ************************
> <action name="simple" class="it.test.SimpleAction">
>    <interceptor-ref name="execAndWait" />
>    <result name="success">/simple.jsp</result>
> </action>
> ***********************
> simple.jsp
> **********************
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <%@taglib prefix="s" uri="/struts-tags"%>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <title>Simple </title>
> </head>
> <body>
> <s:actionmessage/>
> </body>
> </html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-3161) When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-3161?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso resolved WW-3161.
---------------------------------

    Resolution: Won't Fix

see comments

> When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)
> -------------------------------------------------------------------------------------------------
>
>                 Key: WW-3161
>                 URL: https://issues.apache.org/struts/browse/WW-3161
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.1.6
>            Reporter: Gustavo De Sanctis
>             Fix For: 2.1.8
>
>
> I have a simple action that extends ActionSupport and uses the execAndWait interceptor.
> In the "execute" method there is a getText("samekey") that fails with:
> java.lang.NullPointerException
>     com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:318)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:191)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:106)
>     com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:80)
>     it.test.SimpleAction.execute(SimpleAction.java:10)
> When using the default interceptor stack, it works fine.
> My guess is that as the action context is threadlocal and as the execAndWait interceptor creates a new thread to handle the request... this new thread has no reference to the action context (infact ActionContext.getContext() returns null when using execAndWait)
> Below the data to reproduce the problem:
> *****************************
> ACTION CLASS: it.test.SimpleAction
> *****************************
> package it.test;
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.ActionSupport;
> public class SimpleAction extends ActionSupport {
> 	public String execute(){
> 		System.out.println(ActionContext.getContext());
> 		addActionMessage(getText("message.sample","ciao"));
> 		return SUCCESS;
> 	}
> }
> ***********************
>  Struts config 
> ************************
> <action name="simple" class="it.test.SimpleAction">
>    <interceptor-ref name="execAndWait" />
>    <result name="success">/simple.jsp</result>
> </action>
> ***********************
> simple.jsp
> **********************
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <%@taglib prefix="s" uri="/struts-tags"%>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <title>Simple </title>
> </head>
> <body>
> <s:actionmessage/>
> </body>
> </html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-3161) When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-3161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46616#action_46616 ] 

Musachy Barroso commented on WW-3161:
-------------------------------------

I18n is tightly coupled with the ValueStack, and as Gustavo said, the ActionContext (and other things as well) are held in threadlocals, so anything that uses the ValueStack, ActionContext or Dispacther cannot be used from another thread.

This is a problem but it can't be fixed without some major refactoring in xwork.

> When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)
> -------------------------------------------------------------------------------------------------
>
>                 Key: WW-3161
>                 URL: https://issues.apache.org/struts/browse/WW-3161
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.1.6
>            Reporter: Gustavo De Sanctis
>             Fix For: 2.1.8
>
>
> I have a simple action that extends ActionSupport and uses the execAndWait interceptor.
> In the "execute" method there is a getText("samekey") that fails with:
> java.lang.NullPointerException
>     com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:318)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:191)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:106)
>     com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:80)
>     it.test.SimpleAction.execute(SimpleAction.java:10)
> When using the default interceptor stack, it works fine.
> My guess is that as the action context is threadlocal and as the execAndWait interceptor creates a new thread to handle the request... this new thread has no reference to the action context (infact ActionContext.getContext() returns null when using execAndWait)
> Below the data to reproduce the problem:
> *****************************
> ACTION CLASS: it.test.SimpleAction
> *****************************
> package it.test;
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.ActionSupport;
> public class SimpleAction extends ActionSupport {
> 	public String execute(){
> 		System.out.println(ActionContext.getContext());
> 		addActionMessage(getText("message.sample","ciao"));
> 		return SUCCESS;
> 	}
> }
> ***********************
>  Struts config 
> ************************
> <action name="simple" class="it.test.SimpleAction">
>    <interceptor-ref name="execAndWait" />
>    <result name="success">/simple.jsp</result>
> </action>
> ***********************
> simple.jsp
> **********************
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <%@taglib prefix="s" uri="/struts-tags"%>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <title>Simple </title>
> </head>
> <body>
> <s:actionmessage/>
> </body>
> </html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-3161) When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)

Posted by "Christian Martin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-3161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46433#action_46433 ] 

Christian Martin commented on WW-3161:
--------------------------------------

Are there any easy workaround on this issue?

> When using execAndWait interceptor, getText() fails with npe (ActionContext.getContext() is null)
> -------------------------------------------------------------------------------------------------
>
>                 Key: WW-3161
>                 URL: https://issues.apache.org/struts/browse/WW-3161
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.1.6
>            Reporter: Gustavo De Sanctis
>             Fix For: 2.1.8
>
>
> I have a simple action that extends ActionSupport and uses the execAndWait interceptor.
> In the "execute" method there is a getText("samekey") that fails with:
> java.lang.NullPointerException
>     com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:318)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:191)
>     com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:106)
>     com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:80)
>     it.test.SimpleAction.execute(SimpleAction.java:10)
> When using the default interceptor stack, it works fine.
> My guess is that as the action context is threadlocal and as the execAndWait interceptor creates a new thread to handle the request... this new thread has no reference to the action context (infact ActionContext.getContext() returns null when using execAndWait)
> Below the data to reproduce the problem:
> *****************************
> ACTION CLASS: it.test.SimpleAction
> *****************************
> package it.test;
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.ActionSupport;
> public class SimpleAction extends ActionSupport {
> 	public String execute(){
> 		System.out.println(ActionContext.getContext());
> 		addActionMessage(getText("message.sample","ciao"));
> 		return SUCCESS;
> 	}
> }
> ***********************
>  Struts config 
> ************************
> <action name="simple" class="it.test.SimpleAction">
>    <interceptor-ref name="execAndWait" />
>    <result name="success">/simple.jsp</result>
> </action>
> ***********************
> simple.jsp
> **********************
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <%@taglib prefix="s" uri="/struts-tags"%>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <title>Simple </title>
> </head>
> <body>
> <s:actionmessage/>
> </body>
> </html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.