Re: calling request.getHEades("user-agent") twice ->NPE?!
- From: GArlington <garlington@xxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 02:53:55 -0800 (PST)
On Jan 31, 7:39 am, Stefanie Ertheld <Stefanie.Ert...@xxxxxxx> wrote:
Hi,
I got the following line of code:
if (request.getHeaders("user-agent") != null &&
request.getHeaders("user-agent").nextElement() != null)
Which throws a NullPointerException at .nextElement().
(I know I could improve the code but thats not the point here)
The api for getHeaders says:
<API>
getHeaders
public java.util.Enumeration getHeaders(java.lang.String name)
Returns all the values of the specified request header as an
Enumeration of String objects.
Some headers, such as Accept-Language can be sent by clients as
several headers each with a different value rather than sending the
header as a comma separated list.
If the request did not include any headers of the specified name,
this method returns an empty Enumeration. The header name is case
insensitive. You can use this method with any request header.
Parameters:
name - a String specifying the header name
Returns:
an Enumeration containing the values of the requested header.
If the request does not have any headers of that name return an empty
enumeration. If the container does not allow access to header
information, return null
</API>
So the important part is probably:
1. If the request did not include any headers of the specified name,
this method returns an empty Enumeration.
2. If the container does not allow access to header information, return null
------
But I don't get why requesting the same header info twice would not be
allowed?!
Any ideas?
Thanks in advance,
Stefanie
Try to assign request.getHeaders("user-agent") to some var and see
what is the value returned, it is probably empty Enumeration (as in 1.
above), then your call to nextElement() on empty Enumeration is what
causing the problem...
.
- Follow-Ups:
- References:
- calling request.getHEades("user-agent") twice ->NPE?!
- From: Stefanie Ertheld
- calling request.getHEades("user-agent") twice ->NPE?!
- Prev by Date: Re: Updating documents in Lucene
- Next by Date: Re: return result to php
- Previous by thread: calling request.getHEades("user-agent") twice ->NPE?!
- Next by thread: Re: calling request.getHEades("user-agent") twice ->NPE?!
- Index(es):
Relevant Pages
|