Hi,
I just found this question in javabeat's mock-3
----------------------------------------------------------------------------
8.Consider the following
JSP code (See exhibit).
What will it print for the very first request to this page as well as the web application that contains this page?
<html><body>
<%
Integer count = (Integer) request.getSession(false).getAttribute("count");
if(count != null )
{
out.println(count);
}
else request.getSession(false).setAttribute("count", new Integer(1));
%>
Hello!
</body></html>
Select 1 correct option.
A.It will print Hello!
B.It will print Hello and will set the count attribute in the session.
C.It will throw a NullPointerException at request time.
D.It will not compile.
---------------------------------------------------------------------------
they have given answer as B but I think answer is C.
Reason :- I think answer C is correct because of the fact that request made by user is "very first request" and so session might not be available.
When session is not available then request.getSession(false) will return "null" and calling any method on null will result into null pointer exception.
Please reply whether I am right/wrong?