Bug 7615

Summary: Cannot Reliably Test for the Existence of Request Attribute
Product: Taglibs Reporter: David Geary <sabreware>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: Windows XP   

Description David Geary 2002-03-29 19:42:04 UTC
I have a servlet that stores an object in request scope and subsequently 
includes a JSP page. In that JSP page, I have these two lines:

    <% System.out.println(request.getAttribute("validate-error") != null); %>
    <c:out value='${request.validate-error != null}'/><br/>

If the object is in request scope, the scriplet prints true; otherwise, it 
prints false. That's what I expected.

Regardless of whether the object is present, the <c:out> tag always prints 

I believe the scriplet and <c:out> action should behave identically.

Oddly enough, if I test against a request parameter instead of a request 
attribute, the <c:out> action works correctly.
Comment 1 Nathan Abramson 2002-03-31 15:56:20 UTC
Technically, this is not a bug.  The problem is that "-" is not a
valid character in an identifier, so the expression is being
interpreted as:

  ${ (request.validate) - (error) != null }

which, after going through all our coercion rules, ends up being
0!=null, or true.

To get the desired behavior, the identifier has to be quoted:

  ${request."validate-error" != null }

This should work properly.

Having said all that, this definitely looks like a usability issue.
It would be nice if the user could somehow be told that "-" is being
used as an operator, which should give some clue as to what's going
on.  Perhaps if we changed "null - null" to be an error, that would
work, but I think there would be many other undesirable effects of
doing that.

In the end, I don't think there's much that can be done besides better
documentation, and perhaps discouraging people from using non-Java
Comment 2 Nathan Abramson 2002-04-01 14:53:14 UTC
A clarification - quoted identifiers are not actually part of the
specified language anymore (bug 7658), so the desired behavior should
be obtained like this:

  ${request ["validate-error"] != null }