You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bruno Klava <bk...@gmail.com> on 2014/05/06 18:30:33 UTC

NPE in ActionSupport.getText() from servlet

Hi,

in order to load a message from a *.properties file from a servlet, I used
to do:

new ActionSupport().getText(messageKey);

It used to work in Struts versions up to 2.3.15.3.

In Struts 2.3.16+ versions, now I get a NPE:

java.lang.NullPointerException
at
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:361)
 at
com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:208)
at
com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:123)
 at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:103)

Is there a new way (or even an old one :) to get messages from a servlet
context?

Thanks in advance,
Bruno

Re: NPE in ActionSupport.getText() from servlet

Posted by Lukasz Lenart <lu...@apache.org>.
2014-05-06 18:30 GMT+02:00 Bruno Klava <bk...@gmail.com>:
> Hi,
>
> in order to load a message from a *.properties file from a servlet, I used
> to do:
>
> new ActionSupport().getText(messageKey);

Do you use it inside Struts action? ActionContext is action specific
which means you cannot access it from outside, from other thread.
Another thing creating actions by new is allowed only in tests as
framework must prepare environment and inject dependencies, if this
worked it was a bug ;-)

> It used to work in Struts versions up to 2.3.15.3.
>
> In Struts 2.3.16+ versions, now I get a NPE:
>
> java.lang.NullPointerException
> at
> com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:361)
>  at
> com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:208)
> at
> com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:123)
>  at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:103)
>
> Is there a new way (or even an old one :) to get messages from a servlet
> context?

Have you tried to use the latest snapshot version? 2.3.18-SNAPSHOT?
Some similar issue was solved already


Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: NPE in ActionSupport.getText() from servlet

Posted by Bruno Klava <bk...@gmail.com>.
Answering my own question:

LocalizedTextUtil.findDefaultText(messageKey, Locale.getDefault())


On Tue, May 6, 2014 at 1:30 PM, Bruno Klava <bk...@gmail.com> wrote:

> Hi,
>
> in order to load a message from a *.properties file from a servlet, I used
> to do:
>
> new ActionSupport().getText(messageKey);
>
> It used to work in Struts versions up to 2.3.15.3.
>
> In Struts 2.3.16+ versions, now I get a NPE:
>
> java.lang.NullPointerException
> at
> com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:361)
>  at
> com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:208)
> at
> com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:123)
>  at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:103)
>
> Is there a new way (or even an old one :) to get messages from a servlet
> context?
>
> Thanks in advance,
> Bruno
>



-- 
Bruno Klava