| Author |
No NullPointerException in JSP
|
Tomasz Nawrot
Greenhorn
Joined: Feb 19, 2012
Posts: 11
|
|
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
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Jan 10, 2002
Posts: 56549
|
|
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?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: No NullPointerException in JSP
|
|
|