Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No NullPointerException in JSP

 
Tomasz Nawrot
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm wondering why I don't get any NullPoinerException when using tags:

I created JSP file and place a tag USER into it like below:

<%@ taglib prefix="myTag" tagdir="/WEB-INF/tags/users" %>
<myTag:user user="${context.currentUser}" >

CurrentUser is taken from context but in DEBUG mode I saw that currentUser is NULL so we pass NULL value as parameter user to the tag.
My tag expect to retrieve user parameter and then it run method isAllowed on that object like follows:

user.tag
----------
<%@attribute name="user" required="true" type="com.mywork.User" %>
<c:if test="${user.allowed}">


I would expect to get here NullPointerException, but everything finshed without any problems. Why ?






 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomasz Nawrot wrote:
I would expect to get here NullPointerException, but everything finshed without any problems. Why ?

when you work with EL , you should keep in mind that EL operator suppresses null silently .
to check null you can use empty operator. one downside of it that it can also return true for non-null value like empty string or collections.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomasz Nawrot wrote:I would expect to get here NullPointerException, but everything finshed without any problems. Why ?

Why would you expect that? The EL Specification specifies how the EL behaves. Have you found a section in that document that states that a null pointer exception should occur in this situation?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic