This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JSP and the fly likes No NullPointerException in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply 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: 56549
    
  14

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]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: No NullPointerException in JSP
 
Similar Threads
Struts 2 tag
Recieve value from another method
User Spring Bean property in a web page
Database connection problem in JSP application
How to Use Spring AOP for Auditing?