Re: do you get error in this url?
maya wrote:
yes looked at logs.. found something very interesting.. it pointed to
line in jsp servlet causing error; it turns out it had to do with
user-agent!! someone had pointed out something about user-agent..
this is code:
String sBrowser = "";
......
sBrowser = request.getHeader("user-agent");
if (sBrowser.indexOf("Gecko") != -1)
sBrowser = "mozilla";
else sBrowser = "ie";
this, specif., was line causing error (acc. to log):
if (sBrowser.indexOf("Gecko") != -1)
(but still not sure WHAT prob is w/this line..)
Let's see, the error message (which you did not reveal to us) says
that that line is throwing a NullPointerException. I guess that means
that a pointer on that line is null!
The only pointer on that line is 'sBrowser'. If 'sBrowser' were null,
then the attempt to call 'indexOf()' on it would raise an NPE. That
is the behavior you observe. Coincidence? You decide!
How could 'sBrowser' be null? Well, you assigned it the return value
from 'request.getHeader("user-agent");'. When there is no user agent,
that call returns null. Another coincidence?
The source of this bug is failure to accommodate all possible return
values from the method - you ignored the possibility of a 'null'
return. This is a similar failing to lack of input validation. Your
code must handle every possible datum it's handed or you will get the
sort of bug you encountered.
Note that NPE is a RuntimeException, a category of exception that
generally indicates programmer error.
--
Lew