You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rohit <ro...@in-rev.com> on 2010/08/26 11:24:41 UTC

NullPointerException while accessing request struts2

Hi,

I am facing a strange error in Struts2, I am getting a null pointer
exception when trying to set attribute into request scope,

Struts Problem Report

Struts has detected an unhandled exception: Messages:
File: org/apache/catalina/connector/Request.java Line number: 1,424
Stacktraces java.lang.NullPointerException

org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:
503)
javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:
284)
com.inrev.bm.action.IRBrandMgmtAction.wrdTwts(IRBrandMgmtAction.java:81)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)

My code is given below,

public class IRBrandMgmtAction extends ActionSupport implements
SessionAware,ServletRequestAware {


private static final long serialVersionUID = 1L;

private Map session;

private HttpServletRequest request; 

private IRWordToTrack wrdtotrack;

private IRBrandMgmtDAO brandMgmtDAO;

private static org.apache.log4j.Logger log =
Logger.getLogger(IRBrandMgmtAction.class);

and the method where this is happening,

public String wrdTwts()
{
    ArrayList<IRBrandTrackBean> messages = null;
    IRDateUtil dtUtil = new IRDateUtil();
    String wordId = request.getParameter("wordId");

    IRUser user = (IRUser) session.get("user");
    IRWordToTrack word = brandMgmtDAO.getWord(Integer.parseInt(wordId));

    if(word!=null)
    {
        messages =
brandMgmtDAO.viewMsgForUser(word.getWord().toUpperCase().trim(), null,
dtUtil.getTimeZoneOffset(user.getTimeZone()));
    }

    request.setAttribute("messages",messages);

    return "tweets";
}

I am using tomcat 6 server.

Regards, Rohit

 


Re: NullPointerException while accessing request struts2

Posted by Dale Newfield <da...@newfield.org>.
On 8/26/10 7:04 AM, Rohit wrote:
> Yes I have done that, it's not that every time I am getting the null pointer
> exception. It's happening randomly.

First I'd track down the code in question and see just what objects are 
getting dereferenced on that line.  If you have any problem that is not 
deterministic, I.E. happens *sometimes* but not in other seemingly 
identical instances, I'd look to race conditions on non-thread-safe 
objects that might be stored in a scope that gets shared between 
threads/requests/etc.

-Dale

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


RE: NullPointerException while accessing request struts2

Posted by Rohit <ro...@in-rev.com>.
Yes I have done that, it's not that every time I am getting the null pointer
exception. It's happening randomly.

Regards,
Rohit 

-----Original Message-----
From: Jan T. Kim [mailto:j.kim@uea.ac.uk] 
Sent: 26 August 2010 16:31
To: user@struts.apache.org
Subject: Re: NullPointerException while accessing request struts2

On Thu, Aug 26, 2010 at 10:24:41AM +0100, Rohit wrote:
> Hi,
> 
> I am facing a strange error in Struts2, I am getting a null pointer
> exception when trying to set attribute into request scope,
> 
> Struts Problem Report
> 
> Struts has detected an unhandled exception: Messages:
> File: org/apache/catalina/connector/Request.java Line number: 1,424
> Stacktraces java.lang.NullPointerException
> 
> org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
>
org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:
> 503)
>
javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:
> 284)
> com.inrev.bm.action.IRBrandMgmtAction.wrdTwts(IRBrandMgmtAction.java:81)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> java.lang.reflect.Method.invoke(Unknown Source)
> 
> My code is given below,

have you implemented a setServletRequest method, as described in the FAQ
at
 
http://struts.apache.org/2.2.1/docs/how-can-we-access-the-httpservletrequest
.html

Best regards, Jan

> public class IRBrandMgmtAction extends ActionSupport implements
> SessionAware,ServletRequestAware {
> 
> 
> private static final long serialVersionUID = 1L;
> 
> private Map session;
> 
> private HttpServletRequest request; 
> 
> private IRWordToTrack wrdtotrack;
> 
> private IRBrandMgmtDAO brandMgmtDAO;
> 
> private static org.apache.log4j.Logger log =
> Logger.getLogger(IRBrandMgmtAction.class);
> 
> and the method where this is happening,
> 
> public String wrdTwts()
> {
>     ArrayList<IRBrandTrackBean> messages = null;
>     IRDateUtil dtUtil = new IRDateUtil();
>     String wordId = request.getParameter("wordId");
> 
>     IRUser user = (IRUser) session.get("user");
>     IRWordToTrack word = brandMgmtDAO.getWord(Integer.parseInt(wordId));
> 
>     if(word!=null)
>     {
>         messages =
> brandMgmtDAO.viewMsgForUser(word.getWord().toUpperCase().trim(), null,
> dtUtil.getTimeZoneOffset(user.getTimeZone()));
>     }
> 
>     request.setAttribute("messages",messages);
> 
>     return "tweets";
> }
> 
> I am using tomcat 6 server.
> 
> Regards, Rohit
> 
>  
> 

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: j.kim@uea.ac.uk                                 |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

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


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


Re: NullPointerException while accessing request struts2

Posted by "Jan T. Kim" <j....@uea.ac.uk>.
On Thu, Aug 26, 2010 at 10:24:41AM +0100, Rohit wrote:
> Hi,
> 
> I am facing a strange error in Struts2, I am getting a null pointer
> exception when trying to set attribute into request scope,
> 
> Struts Problem Report
> 
> Struts has detected an unhandled exception: Messages:
> File: org/apache/catalina/connector/Request.java Line number: 1,424
> Stacktraces java.lang.NullPointerException
> 
> org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
> org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:
> 503)
> javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:
> 284)
> com.inrev.bm.action.IRBrandMgmtAction.wrdTwts(IRBrandMgmtAction.java:81)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> java.lang.reflect.Method.invoke(Unknown Source)
> 
> My code is given below,

have you implemented a setServletRequest method, as described in the FAQ
at
    http://struts.apache.org/2.2.1/docs/how-can-we-access-the-httpservletrequest.html

Best regards, Jan

> public class IRBrandMgmtAction extends ActionSupport implements
> SessionAware,ServletRequestAware {
> 
> 
> private static final long serialVersionUID = 1L;
> 
> private Map session;
> 
> private HttpServletRequest request; 
> 
> private IRWordToTrack wrdtotrack;
> 
> private IRBrandMgmtDAO brandMgmtDAO;
> 
> private static org.apache.log4j.Logger log =
> Logger.getLogger(IRBrandMgmtAction.class);
> 
> and the method where this is happening,
> 
> public String wrdTwts()
> {
>     ArrayList<IRBrandTrackBean> messages = null;
>     IRDateUtil dtUtil = new IRDateUtil();
>     String wordId = request.getParameter("wordId");
> 
>     IRUser user = (IRUser) session.get("user");
>     IRWordToTrack word = brandMgmtDAO.getWord(Integer.parseInt(wordId));
> 
>     if(word!=null)
>     {
>         messages =
> brandMgmtDAO.viewMsgForUser(word.getWord().toUpperCase().trim(), null,
> dtUtil.getTimeZoneOffset(user.getTimeZone()));
>     }
> 
>     request.setAttribute("messages",messages);
> 
>     return "tweets";
> }
> 
> I am using tomcat 6 server.
> 
> Regards, Rohit
> 
>  
> 

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: j.kim@uea.ac.uk                                 |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

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