8

Yesterday I appeared in an interview. The interviewer shows me this code and asked-

<c:when test='${hobby.equals("hobby1")}'>

Why there is no null pointer, while the value of hobby is null

Code is as-

In Sevlet class-

request.setAttribute("hobby", null);
request.getRequestDispatcher("display.jsp").forward(request, response);

In display.jsp-

<c:when test='${hobby.equals("hobby1")}'>
  • 1
    JSTL and EL are used to render view hence exception and null variable are treated with blank white space. – Jafar Ali Jun 03 '15 at 11:11

1 Answers1

11

JSTL nearly always suppresses NullPointerExceptions. There is a brief discussion here and more detail can be found in section 3.6 of the JSTL spec.

Chris K
  • 11,622
  • 1
  • 36
  • 49