You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rahul Thakur <ra...@gmail.com> on 2007/04/10 05:57:36 UTC

NullPointerException with Parameters.getParameterValues(String)

Hi,

I am dropping this note after spending hours trying to figure out why
my webapp encounters an NPE trying to obtain a param from request.

Scenario:
Moving an old web app from JRun to Tomcat 5.5.23. The app uses custom
taglibs that provide for user authentication and login and this is
where I am encountering the issue. When I try and input the username
and password in the Login form for the admin console and submit it, I
get the following error (and trace).

Much appreciate if anyone can shed some light, or have any suggestions.

Thanks in advance,

Rahul


----- Quoted Error ----

HTTP Status 500

type Exception report

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception org.apache.jasper.JasperException
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:476)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



root cause java.lang.NullPointerException
	java.util.Hashtable.get(Hashtable.java:333)
	org.apache.tomcat.util.http.Parameters.getParameterValues(Parameters.java:193)
	org.apache.tomcat.util.http.Parameters.getParameter(Parameters.java:238)
	org.apache.catalina.connector.Request.getParameter(Request.java:1007)
	org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:353)
	eluminet.wlp.modules.users.servlet.tags.UserLoginTag.doStartTag(UserLoginTag.java:101)
	org.apache.jsp.admin.index_jsp._jspService(index_jsp.java:81)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

----- End of Error -----


Also, here is the relevant snippet from the taglib handler
implementation which is blowing up on the first call to
pageContext.getRequest ().getParameter (username).

----- quote ----

            username = pageContext.getRequest ().getParameter (username);
            System.out.println ("param : 'username' , value: '" +
username + "'");
            password = pageContext.getRequest ().getParameter (password);
            System.out.println ("param : 'password' , value: '" +
password + "'");
            logout = pageContext.getRequest ().getParameter (logout);
            System.out.println ("param : 'logout' , value: '" + logout + "'");

------ end quote -----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Rahul Thakur <ra...@gmail.com>.
Yes I noticed that bug report. Here's the relevant snippet for the login form.

TIA,
Rahul

----- snip --------

    <div style="position:absolute; top:240px; left:55%; z-index:1;">
      <form name="loginform" action="/admin/index.jsp" method="post">
        <table width=200 cellpadding=0 cellspacing=0>
          <tr>
            <td width=1 height=19><img
src="/admin/img/login/login_boxheaderleft.gif"></td>
            <td width="100%" height=19
background="/admin/img/login/login_boxheaderbg.gif">&nbsp;&nbsp;<span
class="Login_boxheader">Login</span></td>
            <td width=7 height=19><img
src="/admin/img/login/login_boxheaderright.gif"></td>
          </tr>

          <tr>
            <td width=1
background="/admin/img/login/login_boxheaderleft.gif"
class="Login_boxbody"></td>
            <td width="100%" class="Login_boxbody">
              <table border=0 cellpadding=5 cellspacing=0 align=center
class="Login_boxbody">
                <tr>
                  <td colspan="3" height="15"><img
src="/images/clear.gif" height="1" width="1"><br></td>
                </tr>
                <tr>
                  <td nowrap>&nbsp;&nbsp;Username</th>

                  <td><input type="text" name="username" size=25
maxlength=32 class="Login_boxpassword" value=""><br></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td align="right">Password</th>
                  <td><input type="password" name="password" size=25
maxlength=32 class="Login_boxpassword"><br></td>
                  <td>&nbsp;</td>
                </tr>

                <tr>
                  <td colspan=2 align=right>
                    <table width="100%" cellpadding=0 cellspacing=0 border=0>
                      <tr>
                        <td valign=center>&nbsp;&nbsp;<span
class="Login_boxerror"></span></td>
                        <td align=right><a href="javascript:
document.loginform.submit ();" onmousedown="changeImage ('btn_login',
'/admin/img/login/login_button_d.gif');" onmouseup="restoreImage
('btn_login');" onmouseout="restoreImage ('btn_login');"><img
name="btn_login" src="/admin/img/login/login_button_u.gif"
border=0></a></td>
                      </tr>
                    </table>
                  </td>

                  <td>&nbsp;</td>
                </tr>
              </table>
            </td>
            <td width=7 align=right
background="/admin/img/login/login_boxbodyright.gif"
class="Login_boxbody"><img
src="/admin/img/login/login_boxbodyright.gif"></td>
          </tr>
          <tr>
            <td colspan = 3 height=1 bgcolor=#003300><img
src="/admin/img/info/info_spacer.gif" height=1></td>
          </tr>

        </form>
      </table>
    </div>

------ end snippet ----




On 4/10/07, Rashmi Rubdi <ra...@gmail.com> wrote:
> Can you also post the HTML Form? May be it has some syntax errors.
>
> Someone has reported a bug that looks a bit similar but is not the same:
> http://mail-archives.apache.org/mod_mbox/tomcat-dev/200401.mbox/%3C20040122133309.29667.qmail@nagoya.betaversion.org%3E
>
> -Rashmi
>
> On 4/9/07, Rahul Thakur <ra...@gmail.com> wrote:
> > root cause java.lang.NullPointerException
> >         java.util.Hashtable.get(Hashtable.java:333)
> >         org.apache.tomcat.util.http.Parameters.getParameterValues(Parameters.java:193)
> >         org.apache.tomcat.util.http.Parameters.getParameter(Parameters.java:238)
> >         org.apache.catalina.connector.Request.getParameter(Request.java:1007)
> >         org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:353)
> >         eluminet.wlp.modules.users.servlet.tags.UserLoginTag.doStartTag(UserLoginTag.java:101)
> >         org.apache.jsp.admin.index_jsp._jspService(index_jsp.java:81)
> >         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
> >         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> >         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
> >         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
> >         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
> >         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> >
> > ----- End of Error -----
> >
> >
> > Also, here is the relevant snippet from the taglib handler
> > implementation which is blowing up on the first call to
> > pageContext.getRequest ().getParameter (username).
> >
> > ----- quote ----
> >
> >             username = pageContext.getRequest ().getParameter (username);
> >             System.out.println ("param : 'username' , value: '" +
> > username + "'");
> >             password = pageContext.getRequest ().getParameter (password);
> >             System.out.println ("param : 'password' , value: '" +
> > password + "'");
> >             logout = pageContext.getRequest ().getParameter (logout);
> >             System.out.println ("param : 'logout' , value: '" + logout + "'");
> >
> > ------ end quote -----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Rashmi Rubdi <ra...@gmail.com>.
Can you also post the HTML Form? May be it has some syntax errors.

Someone has reported a bug that looks a bit similar but is not the same:
http://mail-archives.apache.org/mod_mbox/tomcat-dev/200401.mbox/%3C20040122133309.29667.qmail@nagoya.betaversion.org%3E

-Rashmi

On 4/9/07, Rahul Thakur <ra...@gmail.com> wrote:
> root cause java.lang.NullPointerException
>         java.util.Hashtable.get(Hashtable.java:333)
>         org.apache.tomcat.util.http.Parameters.getParameterValues(Parameters.java:193)
>         org.apache.tomcat.util.http.Parameters.getParameter(Parameters.java:238)
>         org.apache.catalina.connector.Request.getParameter(Request.java:1007)
>         org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:353)
>         eluminet.wlp.modules.users.servlet.tags.UserLoginTag.doStartTag(UserLoginTag.java:101)
>         org.apache.jsp.admin.index_jsp._jspService(index_jsp.java:81)
>         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
>         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
>         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> ----- End of Error -----
>
>
> Also, here is the relevant snippet from the taglib handler
> implementation which is blowing up on the first call to
> pageContext.getRequest ().getParameter (username).
>
> ----- quote ----
>
>             username = pageContext.getRequest ().getParameter (username);
>             System.out.println ("param : 'username' , value: '" +
> username + "'");
>             password = pageContext.getRequest ().getParameter (password);
>             System.out.println ("param : 'password' , value: '" +
> password + "'");
>             logout = pageContext.getRequest ().getParameter (logout);
>             System.out.println ("param : 'logout' , value: '" + logout + "'");
>
> ------ end quote -----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

Robert Harper wrote:
> Try username. I'm surprised the compiler doesn't complain that username is
> being used without being initialized. If it didn't, the compiler probably
> set username to be null.

I don't know of a single compiler that will initialize a local variable
to NULL for you.

> You need to pass a valid string to the method getParameter();
>
> Try something more like:
> 
> String username = null;
> Username = pageContext().getRequest().getParameter( "username" );

Oh, hey. I didn't notice that the OP didn't have "username" in quotes.
He's probably passing NULL to getParameter(). Yeah, that'll do it.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGHQsU9CaO5/Lv0PARAlkqAJwJbr312EAGnsGqZH4S/bPv7vh51QCggTti
UmY0MCSQ+KPvokEMOOpVeBM=
=+F/r
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Rahul Thakur <ra...@gmail.com>.
Hi Chris,

>
> Rahul Thakur wrote:
> > Looks like it was the 'username'. The username is being initialised in
> > the taglib handler implementation but the behaviour differs between
> > JRun and Tomcat.
>
> That should not be the case. The servlet spec is quite clear about the
> order of execution of the various init/begin/body/end taglib calls. Are
> you sure you haven't changed anything?
>
> > Now this can also accept other attributes (if the expected request
> > param names were different). I updated it for Tomcat like this:
> >
> > <users:login loginpage="login.jsp" logout="logout" username="username"
> > password="password" />
>
> Why would it have to change for Tomcat?

This particular web app was coded up 5+ years ago and deployed on
JRun. I am not sure if the Servlet spec then was clear on taglib
lifecycle or not (I admit I haven't read the spec!)


>
> > While 'username', 'password' and 'logout' are initialised to the
> > default values in the taglib handler implementation, the setter method
> > for these attributes still gets called when they are not specified in
> > the JSP, and NULL values are assumed for them. That's the only
> > explanation I can think of :-)
>
> Sounds like it might happen that way. If you have a default value for
> "username" (and friends), why not set those defaults in the
> setUsername(String) method and use the default when NULL is passed?
>
> Also, why is a setter being called on the tag handler when there is no
> attribute value specified? Something sounds fishy. Does adding
> 'username="username"' fix the problem when running under Tomcat?

Yes, adding those attributes to the taglib works on Tomcat.  Another
difference that Robert pointed out in an earlier email on this thread
was about the Request 'Parameter' objects not being
created/assimilated by Tomcat container when another Servlet or Filter
makes a call to Request.getInputStream() or getReader(). I did not hit
any issues on JRun w.r.t this.

Rahul

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rahul,

Rahul Thakur wrote:
> Looks like it was the 'username'. The username is being initialised in
> the taglib handler implementation but the behaviour differs between
> JRun and Tomcat.

That should not be the case. The servlet spec is quite clear about the
order of execution of the various init/begin/body/end taglib calls. Are
you sure you haven't changed anything?

> Now this can also accept other attributes (if the expected request
> param names were different). I updated it for Tomcat like this:
> 
> <users:login loginpage="login.jsp" logout="logout" username="username"
> password="password" />

Why would it have to change for Tomcat?

> While 'username', 'password' and 'logout' are initialised to the
> default values in the taglib handler implementation, the setter method
> for these attributes still gets called when they are not specified in
> the JSP, and NULL values are assumed for them. That's the only
> explanation I can think of :-)

Sounds like it might happen that way. If you have a default value for
"username" (and friends), why not set those defaults in the
setUsername(String) method and use the default when NULL is passed?

Also, why is a setter being called on the tag handler when there is no
attribute value specified? Something sounds fishy. Does adding
'username="username"' fix the problem when running under Tomcat?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGHQvw9CaO5/Lv0PARAr/ZAJ9q1tAU9JihfSpO1vkvpIpZzqRxHACdGu6V
qYgJxerB+azi5kQfeGNKPqM=
=WUa5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Rahul Thakur <ra...@gmail.com>.
Looks like it was the 'username'. The username is being initialised in
the taglib handler implementation but the behaviour differs between
JRun and Tomcat.

In the layout template jsp for the admin console, we use a taglib that
checks if a user is logged in or not. The following snippet works on
JRun.

<users:login loginpage="login.jsp" />

Now this can also accept other attributes (if the expected request
param names were different). I updated it for Tomcat like this:

<users:login loginpage="login.jsp" logout="logout" username="username"
password="password" />

While 'username', 'password' and 'logout' are initialised to the
default values in the taglib handler implementation, the setter method
for these attributes still gets called when they are not specified in
the JSP, and NULL values are assumed for them. That's the only
explanation I can think of :-)

What is the correct behaviour? Any ideas.

Cheers,

Rahul



On 4/11/07, Robert Harper <ro...@iat-cti.com> wrote:
> Try username. I'm surprised the compiler doesn't complain that username is
> being used without being initialized. If it didn't, the compiler probably
> set username to be null.
>
> You need to pass a valid string to the method getParameter();
>
> Try something more like:
>
> String username = null;
> Username = pageContext().getRequest().getParameter( "username" );
>
>
>
> Robert S. Harper
> Senior Engineer
> Information Access Technology, Inc.
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: NullPointerException with Parameters.getParameterValues(String)

Posted by Robert Harper <ro...@iat-cti.com>.
Try username. I'm surprised the compiler doesn't complain that username is
being used without being initialized. If it didn't, the compiler probably
set username to be null.

You need to pass a valid string to the method getParameter();

Try something more like:

String username = null;
Username = pageContext().getRequest().getParameter( "username" );



Robert S. Harper
Senior Engineer
Information Access Technology, Inc.



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 4/10/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
>
> Huh? Are you suggesting that this will cause an NPE:
>
> String username;
>
> ...
>
> username = pageContext.getRequest().getParameter(username);
>
>
> ??!
>
> That's simply not true.
>

Sorry you are right, this code doesn't even compile leave alone
generate a NPE. So the problem is that some other object is Null
somewhere :

      String username;
      pageContext.getRequest().getParameter(username);

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rashmi,

Rashmi Rubdi wrote:
> From looking at the following snippet I assume that username, password
> and logout are initialized as in:
> 
> String username ="username";
> String password ="password";
> String logout="logout";
> 
> If the above are not initialized then you would get NPE.

Huh? Are you suggesting that this will cause an NPE:

String username;

...

username = pageContext.getRequest().getParameter(username);


??!

That's simply not true.

Rahul, are you (or any of your filters) ever calling
Request.getInputStream or Request.getReader /before/ you make any calls
to Request.getParameter*()? If so, you could be tripping-up Tomcat's
ability to collect request parameters. I didn't think it would cause an
NPE... I thought it usually threw an IllegalStateException. Also, it
looks like Tomcat has assembled the Parameters object already... hmm...

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGG4J59CaO5/Lv0PARApbGAJ9aaJGEkny6N/2qazHkfay+uMV9PgCghPFj
XA6iBhZvQHaKEgPxAgu5cZ0=
=FvGX
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: NullPointerException with Parameters.getParameterValues(String)

Posted by Rashmi Rubdi <ra...@gmail.com>.
>From looking at the following snippet I assume that username, password
and logout are initialized as in:

String username ="username";
String password ="password";
String logout="logout";

If the above are not initialized then you would get NPE.

On 4/9/07, Rahul Thakur <ra...@gmail.com> wrote:

>
>             username = pageContext.getRequest ().getParameter (username);
>             System.out.println ("param : 'username' , value: '" +
> username + "'");
>             password = pageContext.getRequest ().getParameter (password);
>             System.out.println ("param : 'password' , value: '" +
> password + "'");
>             logout = pageContext.getRequest ().getParameter (logout);
>             System.out.println ("param : 'logout' , value: '" + logout + "'");
>

Another point is that the form doesn't have a submit button, but a
Javascript based submit

<a href="javascript:
document.loginform.submit ();" onmousedown="changeImage ('btn_login',
'/admin/img/login/login_button_d.gif');" onmouseup="restoreImage
('btn_login');" onmouseout="restoreImage ('btn_login');"><img
name="btn_login" src="/admin/img/login/login_button_u.gif"
border=0></a>

, does the Javascript code properly submit the values? You could try
temporarily replacing it with a html submit button within the form, if
the issue still persists.

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org