aspose file tools*
The moose likes JSP and the fly likes No NullPointerException in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "No NullPointerException in JSP" Watch "No NullPointerException in JSP" New topic
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: 60057
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No NullPointerException in JSP
 
Similar Threads
Struts 2 tag
User Spring Bean property in a web page
Recieve value from another method
Database connection problem in JSP application
How to Use Spring AOP for Auditing?